/////////////////////////////////////////////////////////////////////////////// // 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 "Step2Visualize.h" #include "StepGiContext.h" #include "StepGsManager.h" #include "StepAPModelContext.h" #include "daiApplicationInstance.h" #include "daiModule.h" #include "daiRepository.h" #include "daiSettings.h" #include "daiModel.h" #include "daiHeaderSection.h" #include "daiAggr/daiList.h" #include "StepAPFile.h" #include "StpXFile.h" #include "Cis2File.h" #include #include #include #define STPX_SCHEMA_NAME "MANAGED_MODEL_BASED_3D_ENGINEERING_DOMAIN_MODEL" #define VIEWER_DEFAULT_AP242_EXP_NAME "AP242_MANAGED_MODEL_BASED_3D_ENGINEERING_MIM_LF" #define NODES_LEVEL_WITHOUT_TV 6 using namespace Step2Visualize; namespace { OdString getFileExtension(OdStepFile* pFile) { const OdString& fileName = pFile->getFileName(); int pos = fileName.reverseFind(L'.'); if (pos > 0) { return fileName.right(fileName.getLength() - pos); } return OdString(L".step"); } OdTv::Units getUnits(OdStepFilePtr pStepDatabase, double& addUnitCoefToMeters) { OdTv::Units tvUnits = OdTv::kMeters; addUnitCoefToMeters = 1.; auto rootIds = pStepDatabase->getRootIds(); if (!rootIds.size()) { ODA_FAIL_M("No root ids!"); return tvUnits; } OdAnsiString unitName, unitPrefix; if (pStepDatabase->getUnitConverter()->getConversionUnitName("length_unit", unitName, unitPrefix)) { if (!unitPrefix.isEmpty()) { if (unitName.iCompare("METRE") == 0) { if (unitPrefix == OD_T("MILLI")) tvUnits = OdTv::kMillimeters; else if (unitPrefix == OD_T("CENTI")) tvUnits = OdTv::kCentimeters; else if (unitPrefix == OD_T("MICRO")) tvUnits = OdTv::kMicrometers; else if (unitPrefix == OD_T("KILO")) tvUnits = OdTv::kKilometers; else addUnitCoefToMeters = pStepDatabase->getUnitConverter()->convertToSIUnit("length_unit", 1); } else if (unitName.iCompare("INCH") == 0) { if (unitPrefix == OD_T("MILLI")) tvUnits = OdTv::kMils; else if (unitPrefix == OD_T("MICRO")) tvUnits = OdTv::kMicroInches; else addUnitCoefToMeters = pStepDatabase->getUnitConverter()->convertToSIUnit("length_unit", 1); } } else if (unitName.iCompare("METRE") == 0) tvUnits = OdTv::kMeters; else if (unitName.iCompare("FOOT") == 0) tvUnits = OdTv::kFeet; else if (unitName.iCompare("INCH") == 0) tvUnits = OdTv::kInches; else if (unitName.iCompare("YARD") == 0) tvUnits = OdTv::kYards; else if (unitName.iCompare("MILE") == 0) tvUnits = OdTv::kMiles; else { ODA_ASSERT(!"User defined Length Unit!"); tvUnits = OdTv::kUserDefined; addUnitCoefToMeters = pStepDatabase->getUnitConverter()->convertToSIUnit("length_unit", 1); } } return tvUnits; } } //***************************************************************************// // 'OdTvVisualizePrcFilerProperties' methods implementation //***************************************************************************// OdTvVisualizeStepFilerProperties::OdTvVisualizeStepFilerProperties() : 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_isMultithreadLoadEnabled(true) , m_countedLoadedThreads(4) , m_pHostAppProgressMeter(NULL) , m_useDictionaryTypePath(true) , m_storeInveseAttributes(false) , m_deflateLevel(6) , m_readChunkSize(0) , m_writeChunkSize(1024) , m_customBgTypeValue(0) , m_envBackgroundParam(nullptr) , m_pInterruptCallback(0) , m_representationTypeSelect(0) , m_isForceUseAP242(true) , m_decompressInMemory(false) , m_maxFileSizeForDecompressInMemory(0) { m_importRect.xmax = 1; m_importRect.xmin = 0; m_importRect.ymax = 0; m_importRect.ymin = 1; } OdTvVisualizeStepFilerProperties::~OdTvVisualizeStepFilerProperties() { } OdRxDictionaryPtr OdTvVisualizeStepFilerProperties::createObject() { return OdRxObjectImpl::createObject(); } void OdTvVisualizeStepFilerProperties::setDefaultColor(OdIntPtr pDefColor) { ODCOLORREF* pColor = (ODCOLORREF*)(pDefColor); if (!pColor) { ODA_ASSERT(false); } m_defaultColor = *pColor; } OdIntPtr OdTvVisualizeStepFilerProperties::getDefaultColor() const { return (OdIntPtr)(&m_defaultColor); } void OdTvVisualizeStepFilerProperties::setPalette(OdIntPtr palette) { const ODCOLORREF* pPalette = (const ODCOLORREF*)(palette); m_pPalette = pPalette; } void OdTvVisualizeStepFilerProperties::setBgColor(OdIntPtr pDefColor) { ODCOLORREF* pColor = (ODCOLORREF*)(pDefColor); if (!pColor) { ODA_ASSERT(false); } m_bgColor = *pColor; } OdIntPtr OdTvVisualizeStepFilerProperties::getBgColor() const { return (OdIntPtr)(&m_bgColor); } OdIntPtr OdTvVisualizeStepFilerProperties::getPalette() const { return (OdIntPtr)(m_pPalette); } void OdTvVisualizeStepFilerProperties::setDeviation(double deviation) { m_deviation = deviation; } double OdTvVisualizeStepFilerProperties::getDeviation() const { return m_deviation; } void OdTvVisualizeStepFilerProperties::setMinPerCircle(OdUInt16 minPerCircle) { m_minPerCircle = minPerCircle; } OdUInt16 OdTvVisualizeStepFilerProperties::getMinPerCircle() const { return m_minPerCircle; } void OdTvVisualizeStepFilerProperties::setMaxPerCircle(OdUInt16 maxPerCircle) { m_maxPerCircle = maxPerCircle; } OdUInt16 OdTvVisualizeStepFilerProperties::getMaxPerCircle() const { return m_maxPerCircle; } OdUInt8 OdTvVisualizeStepFilerProperties::getModelerType() const { return m_modelerType; } void Step2Visualize::OdTvVisualizeStepFilerProperties::setBrepToleranceType(OdUInt8 type) { m_brepToleranceType = type; } OdUInt8 Step2Visualize::OdTvVisualizeStepFilerProperties::getBrepToleranceType() const { return m_brepToleranceType; } void Step2Visualize::OdTvVisualizeStepFilerProperties::setBrepToleranceDynamic(double coef) { m_brepToleranceDynamic = coef; } double Step2Visualize::OdTvVisualizeStepFilerProperties::getBrepToleranceDynamic() const { return m_brepToleranceDynamic; } void Step2Visualize::OdTvVisualizeStepFilerProperties::setBrepToleranceStatic(double coef) { m_brepToleranceStatic = coef; } double Step2Visualize::OdTvVisualizeStepFilerProperties::getBrepToleranceStatic() const { return m_brepToleranceStatic; } void OdTvVisualizeStepFilerProperties::setModelerType(OdUInt8 type) { m_modelerType = type; } void OdTvVisualizeStepFilerProperties::setHostAppProgressMeter(OdIntPtr pProgressMeter) { m_pHostAppProgressMeter = (OdTvHostAppProgressMeter*)pProgressMeter; } OdIntPtr OdTvVisualizeStepFilerProperties::getHostAppProgressMeter() const { return (OdIntPtr)m_pHostAppProgressMeter; } void OdTvVisualizeStepFilerProperties::setMultithreadingEnable(bool isEnabled) { m_isMultithreadLoadEnabled = isEnabled; } bool OdTvVisualizeStepFilerProperties::getMultithreadingEnable() const { return m_isMultithreadLoadEnabled; } void OdTvVisualizeStepFilerProperties::setThreadsCount(OdInt16 countThreads) { m_countedLoadedThreads = countThreads; } OdInt16 OdTvVisualizeStepFilerProperties::getThreadsCount() const { return m_countedLoadedThreads; } void Step2Visualize::OdTvVisualizeStepFilerProperties::setCustomBgTypeValue(OdInt16 customBgValue) { m_customBgTypeValue = customBgValue; } OdInt16 Step2Visualize::OdTvVisualizeStepFilerProperties::getCustomBgTypeValue() const { return m_customBgTypeValue; } void Step2Visualize::OdTvVisualizeStepFilerProperties::setEnvBackgroundParam(OdIntPtr envParam) { OdTvEnvBackgroundImportParameters* pEnvBackgroundParam = reinterpret_cast(envParam); if (!pEnvBackgroundParam) { ODA_ASSERT(false); } m_envBackgroundParam = pEnvBackgroundParam; } OdIntPtr Step2Visualize::OdTvVisualizeStepFilerProperties::getEnvBackgroundParam() const { return reinterpret_cast(m_envBackgroundParam); } void Step2Visualize::OdTvVisualizeStepFilerProperties::setRepresentationTypeSelect(OdInt32 representationTypeSelect) { m_representationTypeSelect = representationTypeSelect; } OdInt32 Step2Visualize::OdTvVisualizeStepFilerProperties::getRepresentationTypeSelect() const { return m_representationTypeSelect; } void Step2Visualize::OdTvVisualizeStepFilerProperties::setDecompressInMemory(bool enable) { m_decompressInMemory = enable; } bool Step2Visualize::OdTvVisualizeStepFilerProperties::getDecompressInMemory() const { return m_decompressInMemory; } void Step2Visualize::OdTvVisualizeStepFilerProperties::setMaxFileSizeForDecompressInMemory(OdUInt16 maxFileSize) { m_maxFileSizeForDecompressInMemory = maxFileSize; } OdUInt16 Step2Visualize::OdTvVisualizeStepFilerProperties::getMaxFileSizeForDecompressInMemory() const { return m_maxFileSizeForDecompressInMemory; } void OdTvVisualizeStepFilerProperties::setUseDictionaryTypePath(bool useDictionaryTypePath) { m_useDictionaryTypePath = useDictionaryTypePath; } bool OdTvVisualizeStepFilerProperties::getUseDictionaryTypePath() const { return m_useDictionaryTypePath; } void OdTvVisualizeStepFilerProperties::setStoreInveseAttributes(bool storeInveseAttributes) { m_storeInveseAttributes = storeInveseAttributes; } bool OdTvVisualizeStepFilerProperties::getStoreInveseAttributes() const { return m_storeInveseAttributes; } void OdTvVisualizeStepFilerProperties::setDeflateLevel(OdUInt16 deflateLevel) { m_deflateLevel = deflateLevel; } OdUInt16 OdTvVisualizeStepFilerProperties::getDeflateLevel() const { return m_deflateLevel; } void OdTvVisualizeStepFilerProperties::setReadChunkSize(OdUInt32 readChunkSize) { m_readChunkSize = readChunkSize; } OdUInt32 OdTvVisualizeStepFilerProperties::getReadChunkSize() const { return m_readChunkSize; } void OdTvVisualizeStepFilerProperties::setWriteChunkSize(OdUInt32 writeChunkSize) { m_writeChunkSize = writeChunkSize; } OdUInt32 OdTvVisualizeStepFilerProperties::getWriteChunkSize() const { return m_writeChunkSize; } bool Step2Visualize::OdTvVisualizeStepFilerProperties::getForceUseAP242() const { return m_isForceUseAP242; } void Step2Visualize::OdTvVisualizeStepFilerProperties::setForceUseAP242(bool newState) { m_isForceUseAP242 = newState; } void OdTvVisualizeStepFilerProperties::setDCRect(OdIntPtr rect) { OdTvDCRect* pRect = (OdTvDCRect*)(rect); if (!pRect) { ODA_ASSERT(false); } m_importRect = *pRect; } OdIntPtr OdTvVisualizeStepFilerProperties::getDCRect() const { return (OdIntPtr)(&m_importRect); } void OdTvVisualizeStepFilerProperties::setAppendTransform(OdIntPtr pTransform) { const OdTvMatrix* pAppendTransform = (const OdTvMatrix*)(pTransform); if (pAppendTransform) { m_appendTransform = *pAppendTransform; } else { m_appendTransform = OdTvMatrix::kIdentity; } } OdIntPtr OdTvVisualizeStepFilerProperties::getAppendTransform() const { return (OdIntPtr)(&m_appendTransform); } void OdTvVisualizeStepFilerProperties::setFeedbackForChooseCallback(OdIntPtr pCallback) { m_pCallback = (OdTvFeedbackForChooseCallback)pCallback; } OdIntPtr OdTvVisualizeStepFilerProperties::getFeedbackForChooseCallback() const { return (OdIntPtr)m_pCallback; } void OdTvVisualizeStepFilerProperties::setInterruptionCallback(OdIntPtr pInterrupt) { m_pInterruptCallback = (OdDAI::InterruptCallback)pInterrupt; } OdIntPtr OdTvVisualizeStepFilerProperties::getInterruptionCallback() const { return (OdIntPtr)m_pInterruptCallback; } namespace Step2Visualize { 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(MultithreadingEnable) ODRX_DECLARE_PROPERTY(ThreadsCount) ODRX_DECLARE_PROPERTY(UseDictionaryTypePath) ODRX_DECLARE_PROPERTY(StoreInveseAttributes) ODRX_DECLARE_PROPERTY(DeflateLevel) ODRX_DECLARE_PROPERTY(ReadChunkSize) ODRX_DECLARE_PROPERTY(WriteChunkSize) ODRX_DECLARE_PROPERTY(IsLogOn) ODRX_DECLARE_PROPERTY(InterruptCallback) ODRX_DECLARE_PROPERTY(CustomBgTypeValue) ODRX_DECLARE_PROPERTY(EnvBackgroundParam) ODRX_DECLARE_PROPERTY(RepresentationTypeSelect) ODRX_DECLARE_PROPERTY(BrepToleranceType) ODRX_DECLARE_PROPERTY(BrepToleranceDynamic) ODRX_DECLARE_PROPERTY(BrepToleranceStatic) ODRX_DECLARE_PROPERTY(ForceUseAP242) ODRX_DECLARE_PROPERTY(NeedCDATreeFontSymbolsConversion) ODRX_DECLARE_PROPERTY(DecompressInMemory) ODRX_DECLARE_PROPERTY(MaxFileSizeForDecompressInMemory) ODRX_DECLARE_PROPERTY(DrawPlaceholderData) ODRX_DECLARE_PROPERTY(DrawInvisibleObjects) ODRX_BEGIN_DYNAMIC_PROPERTY_MAP(OdTvVisualizeStepFilerProperties); 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(MultithreadingEnable) ODRX_GENERATE_PROPERTY(ThreadsCount) ODRX_GENERATE_PROPERTY(UseDictionaryTypePath) ODRX_GENERATE_PROPERTY(StoreInveseAttributes) ODRX_GENERATE_PROPERTY(DeflateLevel) ODRX_GENERATE_PROPERTY(ReadChunkSize) ODRX_GENERATE_PROPERTY(WriteChunkSize) ODRX_GENERATE_PROPERTY(IsLogOn) ODRX_GENERATE_PROPERTY(InterruptCallback) ODRX_GENERATE_PROPERTY(CustomBgTypeValue) ODRX_GENERATE_PROPERTY(EnvBackgroundParam) ODRX_GENERATE_PROPERTY(RepresentationTypeSelect) ODRX_GENERATE_PROPERTY(BrepToleranceType) ODRX_GENERATE_PROPERTY(BrepToleranceDynamic) ODRX_GENERATE_PROPERTY(BrepToleranceStatic) ODRX_GENERATE_PROPERTY(ForceUseAP242) ODRX_GENERATE_PROPERTY(NeedCDATreeFontSymbolsConversion) ODRX_GENERATE_PROPERTY(DecompressInMemory) ODRX_GENERATE_PROPERTY(MaxFileSizeForDecompressInMemory) ODRX_GENERATE_PROPERTY(DrawPlaceholderData) ODRX_GENERATE_PROPERTY(DrawInvisibleObjects) ODRX_END_DYNAMIC_PROPERTY_MAP(OdTvVisualizeStepFilerProperties); ODRX_DEFINE_PROPERTY_METHODS(Palette, OdTvVisualizeStepFilerProperties, getPalette, setPalette, getIntPtr); ODRX_DEFINE_PROPERTY_METHODS(DCRect, OdTvVisualizeStepFilerProperties, getDCRect, setDCRect, getIntPtr); ODRX_DEFINE_PROPERTY_METHODS(ObjectNaming, OdTvVisualizeStepFilerProperties, getObjectNaming, setObjectNaming, getBool); ODRX_DEFINE_PROPERTY_METHODS(StoreSourceObjects, OdTvVisualizeStepFilerProperties, getStoreSourceObjects, setStoreSourceObjects, getBool); ODRX_DEFINE_PROPERTY_METHODS(ClearEmptyObjects, OdTvVisualizeStepFilerProperties, getClearEmptyObjects, setClearEmptyObjects, getBool); ODRX_DEFINE_PROPERTY_METHODS(RearrangeObjects, OdTvVisualizeStepFilerProperties, getRearrangeObjects, setRearrangeObjects, getBool); ODRX_DEFINE_PROPERTY_METHODS(AppendTransform, OdTvVisualizeStepFilerProperties, getAppendTransform, setAppendTransform, getIntPtr); ODRX_DEFINE_PROPERTY_METHODS(FeedbackForChooseCallback, OdTvVisualizeStepFilerProperties, getFeedbackForChooseCallback, setFeedbackForChooseCallback, getIntPtr); ODRX_DEFINE_PROPERTY_METHODS(InterruptCallback, OdTvVisualizeStepFilerProperties, getInterruptionCallback, setInterruptionCallback, getIntPtr); ODRX_DEFINE_PROPERTY_METHODS(DefaultEntityColor, OdTvVisualizeStepFilerProperties, getDefaultColor, setDefaultColor, getIntPtr); ODRX_DEFINE_PROPERTY_METHODS(Deviation, OdTvVisualizeStepFilerProperties, getDeviation, setDeviation, getDouble); ODRX_DEFINE_PROPERTY_METHODS(MinPerCircle, OdTvVisualizeStepFilerProperties, getMinPerCircle, setMinPerCircle, getIntPtr) ODRX_DEFINE_PROPERTY_METHODS(MaxPerCircle, OdTvVisualizeStepFilerProperties, getMaxPerCircle, setMaxPerCircle, getIntPtr) ODRX_DEFINE_PROPERTY_METHODS(NeedCDATree, OdTvVisualizeStepFilerProperties, getNeedCDATree, setNeedCDATree, getBool) ODRX_DEFINE_PROPERTY_METHODS(ModelerType, OdTvVisualizeStepFilerProperties, getModelerType, setModelerType, getIntPtr) ODRX_DEFINE_PROPERTY_METHODS(NeedCollectPropertiesInCDA, OdTvVisualizeStepFilerProperties, getNeedCollectPropertiesInCDA, setNeedCollectPropertiesInCDA, getBool); ODRX_DEFINE_PROPERTY_METHODS(UseCustomBgColor, OdTvVisualizeStepFilerProperties, getUseCustomBgColor, setUseCustomBgColor, getBool); ODRX_DEFINE_PROPERTY_METHODS(BgEntityColor, OdTvVisualizeStepFilerProperties, getBgColor, setBgColor, getIntPtr); ODRX_DEFINE_PROPERTY_METHODS(HostAppProgressMeter, OdTvVisualizeStepFilerProperties, getHostAppProgressMeter, setHostAppProgressMeter, getIntPtr); ODRX_DEFINE_PROPERTY_METHODS(MultithreadingEnable, OdTvVisualizeStepFilerProperties, getMultithreadingEnable, setMultithreadingEnable, getBool); ODRX_DEFINE_PROPERTY_METHODS(ThreadsCount, OdTvVisualizeStepFilerProperties, getThreadsCount, setThreadsCount, getIntPtr); ODRX_DEFINE_PROPERTY_METHODS(UseDictionaryTypePath, OdTvVisualizeStepFilerProperties, getUseDictionaryTypePath, setUseDictionaryTypePath, getBool); ODRX_DEFINE_PROPERTY_METHODS(StoreInveseAttributes, OdTvVisualizeStepFilerProperties, getStoreInveseAttributes, setStoreInveseAttributes, getBool); ODRX_DEFINE_PROPERTY_METHODS(DeflateLevel, OdTvVisualizeStepFilerProperties, getDeflateLevel, setDeflateLevel, getIntPtr); ODRX_DEFINE_PROPERTY_METHODS(ReadChunkSize, OdTvVisualizeStepFilerProperties, getReadChunkSize, setReadChunkSize, getIntPtr); ODRX_DEFINE_PROPERTY_METHODS(WriteChunkSize, OdTvVisualizeStepFilerProperties, getWriteChunkSize, setWriteChunkSize, getIntPtr); ODRX_DEFINE_PROPERTY_METHODS(IsLogOn, OdTvVisualizeStepFilerProperties, getIsLogOn, setIsLogOn, getBool); ODRX_DEFINE_PROPERTY_METHODS(CustomBgTypeValue, OdTvVisualizeStepFilerProperties, getCustomBgTypeValue, setCustomBgTypeValue, getIntPtr); ODRX_DEFINE_PROPERTY_METHODS(EnvBackgroundParam, OdTvVisualizeStepFilerProperties, getEnvBackgroundParam, setEnvBackgroundParam, getIntPtr); ODRX_DEFINE_PROPERTY_METHODS(RepresentationTypeSelect, OdTvVisualizeStepFilerProperties, getRepresentationTypeSelect, setRepresentationTypeSelect, getIntPtr); ODRX_DEFINE_PROPERTY_METHODS(BrepToleranceType, OdTvVisualizeStepFilerProperties, getBrepToleranceType, setBrepToleranceType, getIntPtr); ODRX_DEFINE_PROPERTY_METHODS(BrepToleranceDynamic, OdTvVisualizeStepFilerProperties, getBrepToleranceDynamic, setBrepToleranceDynamic, getDouble); ODRX_DEFINE_PROPERTY_METHODS(BrepToleranceStatic, OdTvVisualizeStepFilerProperties, getBrepToleranceStatic, setBrepToleranceStatic, getDouble); ODRX_DEFINE_PROPERTY_METHODS(ForceUseAP242, OdTvVisualizeStepFilerProperties, getForceUseAP242, setForceUseAP242, getBool); ODRX_DEFINE_PROPERTY_METHODS(NeedCDATreeFontSymbolsConversion, OdTvVisualizeStepFilerProperties, getNeedCDATreeFontSymbolsConversion, setNeedCDATreeFontSymbolsConversion, getBool); ODRX_DEFINE_PROPERTY_METHODS(DecompressInMemory, OdTvVisualizeStepFilerProperties, getDecompressInMemory, setDecompressInMemory, getBool); ODRX_DEFINE_PROPERTY_METHODS(MaxFileSizeForDecompressInMemory, OdTvVisualizeStepFilerProperties, getMaxFileSizeForDecompressInMemory, setMaxFileSizeForDecompressInMemory, getIntPtr); ODRX_DEFINE_PROPERTY_METHODS(DrawPlaceholderData, OdTvVisualizeStepFilerProperties, getDrawPlaceholderData, setDrawPlaceholderData, getBool); ODRX_DEFINE_PROPERTY_METHODS(DrawInvisibleObjects, OdTvVisualizeStepFilerProperties, getDrawInvisibleObjects, setDrawInvisibleObjects, getBool); } //***************************************************************************// // 'OdTvVisualizeStepFiler' methods implementation //***************************************************************************// namespace { OdString extractFontSymbols(const OdString& input, OdStepHostAppServices* pAppServices) { OdString convertedText; static OdString fontName = OD_T("Y14.5M-2009"); const OdDAISpecSymbolDictionary* symbolMapping = pAppServices ? &pAppServices->getFontSpecSymbolMapping(fontName) : nullptr; if (symbolMapping == nullptr) { //Nothing to do.. ODA_FAIL_M_ONCE("Symbol mapping table is null."); return input; } bool bracketMode = false; OdString currentFragment; for (int charIndex = 0; charIndex < input.getLength(); ++charIndex) { if (input[charIndex] == '{') { ODA_ASSERT(bracketMode == false && "bad syntax"); bracketMode = true; if (currentFragment.isEmpty() == true) { continue; } convertedText += currentFragment; currentFragment.empty(); continue; } else if (input[charIndex] == '}') { ODA_ASSERT(bracketMode == true && "bad syntax"); bracketMode = false; if (currentFragment.isEmpty() == true) { continue; } auto symbolIterator = symbolMapping->find(currentFragment); if (symbolIterator == symbolMapping->end()) { ODA_FAIL_M_ONCE("Can not map current fragment into a symbol."); convertedText += "{" + currentFragment + "}"; currentFragment.empty(); continue; } currentFragment.empty(); const auto& symbol = symbolIterator->second; if (symbol == OD_T("\n")) { convertedText += "..."; continue; } convertedText += symbol; continue; } currentFragment += input[charIndex]; } if (currentFragment.isEmpty() == false) { ODA_ASSERT(bracketMode == false); convertedText += currentFragment; } return convertedText; } } OdTvVisualizeStepFiler::OdTvVisualizeStepFiler() : OdTvVisualizeFiler() , m_properties(OdTvVisualizeStepFilerProperties::createObject()) { } //int OdTvVisualizeStepFiler::getChoosedRepresentationContexts(OdStepFilePtr pStepFile, OdTvFilerFeedbackForChooseObject& filerFeedbackForChoose, bool& bCanceled) const //{ // m_selContexts.clear(); // // OdDAI::ModelPtr pModel = pStepFile->getModel(); // // if (pModel.isNull()) // { // ODA_ASSERT_ONCE(pModel.get()); // return -1; // } // // if (!m_properties->has(OD_T("FeedbackForChooseCallback")) || // m_properties->getFeedbackForChooseCallback() == 0) // return odSelectRepresentationContextsByDefault(pModel); // // OdTvFilerFeedbackItemForChooseArray* pFilerFeedbackForChooseArray = filerFeedbackForChoose.getFilerFeedbackItemForChooseArrayPtr(); // if (pFilerFeedbackForChooseArray == NULL) // return odSelectRepresentationContextsByDefault(pModel); // // return odSelectRepresentationContextsByDefault(pModel); //} OdAnsiString OdTvVisualizeStepFiler::getLog(OdDAI::SessionPtr& pSession, OdStepFilePtr 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 += "Read with schema:\t\t "; logString += pFile->getModel()->underlyingSchemaName(); logString += "\n"; //OdStepHostAppServices* pServices = pFile->getAppServices(); //logString += "Produced by:\t\t "; //logString += "ODA STEP 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 OdTvVisualizeStepFiler::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); } OdTvDatabaseId OdTvVisualizeStepFiler::loadFrom(OdStreamBuf* pBuffer, OdTvFilerTimeProfiling* pProfileRes /*= NULL*/, OdTvResult* rc /*= NULL*/) const { OdTvDatabaseId idDb; import(idDb, pBuffer, OdStepFilePtr(), pProfileRes, rc); return idDb; } OdTvDatabaseId OdTvVisualizeStepFiler::loadFrom(OdDbBaseDatabase* pDatabase, OdTvFilerTimeProfiling* pProfileRes /*= NULL*/, OdTvResult* rc /*= NULL*/) const { OdTvDatabaseId tvDbId; import(tvDbId, NULL, pDatabase, pProfileRes, rc); return tvDbId; } OdTvDatabaseId OdTvVisualizeStepFiler::generate(OdTvFilerTimeProfiling* pProfileRes) const { OdTvDatabaseId tvDbId; // does nothing return tvDbId; } OdTvModelId OdTvVisualizeStepFiler::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 OdTvVisualizeStepFiler::appendFrom(const OdTvDatabaseId& databaseId, OdStreamBuf* pBuffer, OdTvFilerTimeProfiling* pProfileRes /*= NULL*/, OdTvResult* rc /*= NULL*/) const { OdTvDatabaseId idTvDb = (OdTvDatabaseId)databaseId; return import(idTvDb, pBuffer, OdStepFilePtr(), pProfileRes, rc); } OdTvModelId OdTvVisualizeStepFiler::appendFrom(const OdTvDatabaseId& databaseId, OdDbBaseDatabase* pDatabase, OdTvFilerTimeProfiling* pProfileRes /*= NULL*/, OdTvResult* rc /*= NULL*/) const { OdTvDatabaseId tvDbId = databaseId; return import(tvDbId, NULL, pDatabase, pProfileRes, rc); } int OdTvVisualizeStepFiler::getActiveViewId(OdGsStepLayoutHelper* 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; } void OdTvVisualizeStepFiler::createCommonDataAccessTree(OdTvDatabasePtr pTvDb, OdDbBaseDatabase* pDatabase, const OdString& strTreeName, const OdTvModelId& modelId /*= OdTvModelId()*/) const { OdStepFilePtr pStepFile = OdStepFile::cast(pDatabase); if (pStepFile.isNull()) { ODA_ASSERT_ONCE("Wrong database class!"); return; } OdDAI::ModelPtr pModel = pStepFile->getModel(); if (pModel.isNull()) { ODA_ASSERT_ONCE("Can not create CDA tree for empty StepFile!"); return; } ::odrxDynamicLinker()->loadModule(L"RxProperties"); //Create CDA tree OdTvCDATreePtr pTree = OdTvCDATree::createObject(); if (m_properties->getNeedCollectPropertiesInCDA()) pTree->createDatabaseHierarchyTree(pStepFile.get(), true); else { std::set props; props.insert(OdTvCDAPropNameForGrouping); pTree->createDatabaseHierarchyTree(pStepFile.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 (OdRxModelTreeBaseNodePtrArray::const_iterator 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 find ONLY first occurance 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, m_properties->getNeedCDATreeFontSymbolsConversion() ? pStepFile->getAppServices() : nullptr); } bool OdTvVisualizeStepFiler::processCDANodeValidWithoutTv(OdRxModelTreeBaseNode* pNode, OdRxModelTreeBaseNode* pParentNode, int level) const { if (level == 0) return true; if (!pNode) return true; OdTvCDATreeNodePtr pTvNode = dynamic_cast(pNode); pTvNode->setNeedGroup(false); pTvNode->setValidWithoutTv(true); const OdRxModelTreeBaseNodePtrArray& children = pNode->getChildren(); if (children.isEmpty()) return true; level--; for (OdRxModelTreeBaseNodePtrArray::const_iterator it = children.begin(); it != children.end(); ++it) { if (!processCDANodeValidWithoutTv(const_cast((*it).get()), pNode, (*it).get()->getNodeName() == OD_T("context_dependent_shape_representation") ? NODES_LEVEL_WITHOUT_TV : level)) return false; } return true; } namespace { int processCDANodeValidWithoutTvLevel(const OdString& name) { //Find manifold_solid_brep inside context_dependent_shape_representation if (name == OD_T("context_dependent_shape_representation")|| name == OD_T("DocumentAssignment")) return NODES_LEVEL_WITHOUT_TV; if (name == OD_T("File References")) return 1; return 0; } } bool OdTvVisualizeStepFiler::processCDANode(OdRxModelTreeBaseNode* pNode, OdRxModelTreeBaseNode* pParentNode, OdDAIHostAppServicesBase* pAppServices) const { if (!pNode) return true; if (pNode->getParents().size() > 1 && pNode->getParents().at(0) != pParentNode) return true; OdTvCDATreeNodePtr pTvNode = dynamic_cast(pNode); if (pAppServices && pTvNode->getFontInfo()) { OdString extractedName = ::extractFontSymbols(pTvNode->getNodeName(), OdStepHostAppServices::cast(pAppServices)); if (extractedName == pTvNode->getNodeName()) pTvNode->setFontInfo(nullptr); else pTvNode->setNodeName(extractedName); } else if (pTvNode->getFontInfo()) { pTvNode->setFontInfo(nullptr); } const OdRxModelTreeBaseNodePtrArray& children = pNode->getChildren(); if (children.isEmpty()) return true; pTvNode->setNeedGroup(false); // pTvNode->setValidWithoutTv(true); if (const int level = ::processCDANodeValidWithoutTvLevel(pNode->getNodeName())) { pTvNode->setValidWithoutTv(true); for (OdRxModelTreeBaseNodePtrArray::const_iterator it = children.begin(); it != children.end(); ++it) { if (!processCDANodeValidWithoutTv(const_cast((*it).get()), pNode, level)) return false; } return true; } for (OdRxModelTreeBaseNodePtrArray::const_iterator it = children.begin(); it != children.end(); ++it) { if (!processCDANode(const_cast((*it).get()), pNode, pAppServices)) return false; } return true; } OdString OdTvVisualizeStepFiler::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 OdTvVisualizeStepFiler::odSelectRepresentationContextsByDefault(OdDAI::ModelPtr pModel) const //{ // const OdDAI::SetOfOdDAIObjectId* setContext = pModel->getEntityExtent(pModel->underlyingSchemaName().compare(STPX_SCHEMA_NAME) ? "GEOMETRIC_REPRESENTATION_CONTEXT": "Part"); // auto nextIterator = setContext ? setContext->createConstIterator() : OdDAI::ConstIteratorPtr(); // // ODA_ASSERT(!nextIterator.isNull() && "pointer cannot be null"); // if (nextIterator.isNull()) // { // return -1; // } // // while (nextIterator->next()) // { // OdDAIObjectId entityId; // if (!(nextIterator->getCurrentMember() >> entityId)) // { // continue; // } // m_selContexts.append(entityId); // } // return m_selContexts.size(); //} void OdTvVisualizeStepFiler::chooseRepresetationsForProducts(OdStepFilePtr pFile) const { OdAPFilePtr pAPFile = OdAPFile::cast(pFile); if (pAPFile.isNull()) return; auto representationPairs = pAPFile->findProductsRepresentationPairs(); if (!representationPairs.isEmpty()) { OdDAIObjectIds hiddenObjects; int mode = m_properties->getRepresentationTypeSelect(); if (mode == 2 && m_properties->has(OD_T("FeedbackForChooseCallback")) && m_properties->getFeedbackForChooseCallback() != 0) { OdTvFilerFeedbackForChooseObject filerFeedbackForChooseRepresentation(OD_T("Representations selection")); OdTvFilerFeedbackItemForChooseArray* pFilerFeedbackForChooseArray = filerFeedbackForChooseRepresentation.getFilerFeedbackItemForChooseArrayPtr(); if (pFilerFeedbackForChooseArray != NULL) { for (auto it : representationPairs) { OdDAIObjectId productId; if (!(it.first.openObject()->getAttr("definition") >> productId)) { ODA_FAIL_M("getAttr error"); return; } OdString productName; productName.format(L"#%I64d %hs\\#%I64d %hs", productId.getHandle(), productId.getNested()->typeName().c_str(), it.first.getHandle(), it.first.getNested()->typeName().c_str()); OdTvFilerFeedbackItemForChoose filerFeedbackForChoose(productName, true); pFilerFeedbackForChooseArray->append(filerFeedbackForChoose); OdDAI::NonPersistentList attributeItem; it.second.openObject()->findUsedInBN("name_attribute.named_item", &attributeItem); OdAnsiString attribute; if (attributeItem.getMemberCount()) { for (auto it = attributeItem.createConstIterator(); it->next();) { OdDAI::OdDAIObjectSDAI* pObj; if (it->getCurrentMember() >> pObj) { pObj->getAttr("attribute_value") >> attribute; } } } productName.format(L"#%I64d %hs\\#%I64d %hs (%hs)", productId.getHandle(), productId.getNested()->typeName().c_str(), it.second.getHandle(), it.second.getNested()->typeName().c_str(), attribute.c_str()); OdTvFilerFeedbackItemForChoose filerFeedbackForChooseAlternative(productName, false); pFilerFeedbackForChooseArray->append(filerFeedbackForChooseAlternative); } // // //show dialog window // ((OdTvFeedbackForChooseCallback)m_properties->getFeedbackForChooseCallback())(filerFeedbackForChooseRepresentation); if (filerFeedbackForChooseRepresentation.getFilerFeedbackItemForChooseArrayPtr()->length() != 0) { for (unsigned int i = 0; i < pFilerFeedbackForChooseArray->size(); ++i) { if (!pFilerFeedbackForChooseArray->at(i).m_bChosen) { hiddenObjects.push_back(i%2? representationPairs[i / 2].second : representationPairs[i / 2].first); } } } } } // else // { // //auto choose representation // for (auto it : productRepresentations) // { // for (auto repIt : it.second) // { // auto attrIt = nameAttributes.find(repIt); // if (attrIt != nameAttributes.cend()) // { //// OdString attribute; //// bool checkAlternative = attrIt->second.openObject()->testAttr("attribute_value"); // if (mode == 0) // hiddenObjects.push_back(repIt); // } // else // if (mode == 1) // hiddenObjects.push_back(repIt); // } // } // } if (!hiddenObjects.isEmpty()) { pFile->getContext().setHiddenObjectsIds(hiddenObjects); pFile->recalcRootIds(); } } // OdDAIObjectIds hiddenObjects; // OdDAI::ModelPtr pModel = pFile->getModel(); // const OdDAI::SetOfOdDAIObjectId* pExtent = pModel->getEntityExtent("shape_definition_representation"); // // if (pExtent && pExtent->getMemberCount()) // { // std::map productRepresentations; // OdDAIObjectId id, productId; // for (auto it = pExtent->createConstIterator(); it->next();) // { // if (it->getCurrentMember() >> id && id.openObject()->getAttr("definition") >> productId) // { // productRepresentations[productId].append(id); // } // } // // for (auto it = productRepresentations.begin(); it != productRepresentations.cend();) // { // if (it->second.size() <= 1) // it = productRepresentations.erase(it); // else // ++it; // } // // if (!productRepresentations.empty()) // { // const OdDAI::SetOfOdDAIObjectId* pAttributeExtent = pModel->getEntityExtent("name_attribute"); // std::map nameAttributes; // if (pAttributeExtent && pAttributeExtent->getMemberCount()) // { // for (auto it = pAttributeExtent->createConstIterator(); it->next();) // { // OdDAIObjectId id, itemId; // if (it->getCurrentMember() >> id && id.openObject()->getAttr("named_item") >> itemId) // { // nameAttributes[itemId] = id; // } // } // } // // int mode = m_properties->getRepresentationTypeSelect(); // // if (mode == 2 && m_properties->has(OD_T("FeedbackForChooseCallback")) && // m_properties->getFeedbackForChooseCallback() != 0) // { // OdTvFilerFeedbackForChooseObject filerFeedbackForChooseRepresentation(OD_T("Representations selection")); // // OdTvFilerFeedbackItemForChooseArray* pFilerFeedbackForChooseArray = filerFeedbackForChooseRepresentation.getFilerFeedbackItemForChooseArrayPtr(); // if (pFilerFeedbackForChooseArray != NULL) // { // for (auto it : productRepresentations) // { // OdString productName; // productName.format(L"#%I64d %hs\\", it.first.getHandle(), it.first.getNested()->typeName().c_str()); // for (auto repIt : it.second) // { // OdString reperesentationName; // // OdDAIObjectId reprId; // if (repIt.openObject()->getAttr("used_representation") >> reprId) // reperesentationName.format(L"#%I64d %hs", reprId.getHandle(), reprId.getNested()->typeName().c_str()); // else // reperesentationName.format(L"#%I64d %hs", repIt.getHandle(), repIt.getNested()->typeName().c_str()); // // OdTvFilerFeedbackItemForChoose filerFeedbackForChoose(productName + reperesentationName, true); // // auto attrIt = nameAttributes.find(repIt); // if (attrIt != nameAttributes.cend()) // { // OdString attribute; // if (attrIt->second.openObject()->getAttr("attribute_value") >> attribute) // { // filerFeedbackForChoose.m_strName.insert(filerFeedbackForChoose.m_strName.getLength(), L" (" + attribute + L")"); //// if (!attribute.compare(OD_T("alternative shape representation"))) // filerFeedbackForChoose.m_bChosen = false; // } // } // pFilerFeedbackForChooseArray->append(filerFeedbackForChoose); // } // } // } // // //show dialog window // // ((OdTvFeedbackForChooseCallback)m_properties->getFeedbackForChooseCallback())(filerFeedbackForChooseRepresentation); // if (filerFeedbackForChooseRepresentation.getFilerFeedbackItemForChooseArrayPtr()->length() != 0) // { // int pos = 0; // for (auto it : productRepresentations) // { // for (auto repIt : it.second) // { // if (!pFilerFeedbackForChooseArray->at(pos).m_bChosen) // { // hiddenObjects.push_back(repIt); // } // ++pos; // } // } // } // } // else // { // //auto choose representation // for (auto it : productRepresentations) // { // for (auto repIt : it.second) // { // auto attrIt = nameAttributes.find(repIt); // if (attrIt != nameAttributes.cend()) // { //// OdString attribute; //// bool checkAlternative = attrIt->second.openObject()->testAttr("attribute_value"); // if (mode == 0) // hiddenObjects.push_back(repIt); // } // else // if (mode == 1) // hiddenObjects.push_back(repIt); // } // } // } // } // } // if (!hiddenObjects.isEmpty()) // { // pFile->getContext().setHiddenObjectsIds(hiddenObjects); // pFile->recalcRootIds(); // } } OdTvGsViewId OdTvVisualizeStepFiler::getActiveTvView(OdTvGsDeviceId& tvDeviceId, int iActViewViewInd) const { OdTvGsDevicePtr pTvDevice = tvDeviceId.openObject(); if (!pTvDevice.isNull()) { return pTvDevice->viewAt(iActViewViewInd); } return OdTvGsViewId(); } OdTvGsDeviceId OdTvVisualizeStepFiler::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 OdTvVisualizeStepFiler::import(OdTvDatabaseId& tvDbId, OdStreamBuf* pBuffer, OdStepFilePtr pDatabase, OdTvFilerTimeProfiling* pProfileRes, OdTvResult* rc) const { if (rc) *rc = tvOk; OdTvModelId idModel; OdString fileName; if (pBuffer) fileName = OdTvDatabaseUtils::getFileNameFromPath(pBuffer->fileName()); else if (!pDatabase.isNull()) fileName = OdTvDatabaseUtils::getFileNameFromPath(pDatabase->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(); ModelerType modelerType = (ModelerType)m_properties->getModelerType(); bool bActivated = !pDatabase.isNull(); OdRxModulePtr pRxPropertiesModule; if (!bActivated) { //SEA: we have to load RxProperties before odStepInitialize() to correct CDA initialization if( m_properties->getNeedCDATree() ) pRxPropertiesModule = odrxDynamicLinker()->loadModule( "RxProperties" ); odStepInitialize(true, true, modelerType); if (m_properties->getIsLogOn()) { OdDAI::SessionPtr pSession = oddaiSession(); if (pSession.isNull()) pSession = oddaiCreateSession(); pSession->startEventRecording(); } } else { odStepInitModelerGeometry(modelerType); } // // Store visualize device module name // OdString moduleName; try { // // Local smart pointer pStepDatabase, so we can release it and uninitialize STEP SDK if // pDatabasePtr wasn't provided, and STEP file should be loaded into this module. // OdStepFilePtr pStepDatabase = pDatabase; if (pStepDatabase.isNull() && pBuffer) { // // No OdStepFile provided, so file should be loaded and released in this module // OdDAI::Settings& setting = OdDAI::settings(); setting.set_ThreadsCount(m_properties->getThreadsCount()); setting.set_multiThreadingMode(m_properties->getMultithreadingEnable() ? OdDAI::MultithreadingMode::MultiThreadPool : OdDAI::MultithreadingMode::Single); setting.set_hdf5useDictionaryTypePath(m_properties->getUseDictionaryTypePath()); setting.set_hdf5storeInverseAttributes(m_properties->getStoreInveseAttributes()); setting.set_hdf5deflateLevel((OdDAI::hdf5DeflateLevel)m_properties->getDeflateLevel()); setting.set_hdf5readChunkSize(m_properties->getReadChunkSize()); setting.set_hdf5writeChunkSize(m_properties->getWriteChunkSize()); if (m_properties->getDecompressInMemory()) svcs.setMaxMemoryBufferSize(m_properties->getMaxFileSizeForDecompressInMemory() * 1024 * 1024); else svcs.setMaxMemoryBufferSize(0); OdDbHostAppProgressMeter* pMeter = (OdDbHostAppProgressMeter*)m_properties->getHostAppProgressMeter(); if (pMeter) svcs.setProgressMeter(pMeter); timing.startMisc(); pStepDatabase = m_properties->getForceUseAP242() ? svcs.readFile(pBuffer, VIEWER_DEFAULT_AP242_EXP_NAME) : svcs.readFile(pBuffer); timing.endMisc(); fileOpenTiming = timing.getMiscTime(); } if (!pStepDatabase.isNull()) { // // Interrupt total timing for ask what representation contexts should be drawn // timing.startMisc(); OdTvFilerFeedbackForChooseObject filerFeedbackForChooseObject(OD_T("Geometric contexts for import")); bool bCanceled = false; // OdStepModelContext context = pStepDatabase->getContext(); //OdArray composedTypes = context.getGeometryComposeTypes(); //int nSelContexts = getChoosedRepresentationContexts(pStepDatabase, filerFeedbackForChooseObject, bCanceled); //context.setGeometryComposeTypes(composedTypes); //pStepDatabase->setContext(context); // //Hide doubled representations chooseRepresetationsForProducts(pStepDatabase); timing.endMisc(); contextSelectionTiming = timing.getMiscTime(); if (!pStepDatabase->getRootIds().isEmpty()) { // // Customize OdStepModelContext // OdStepModelContext& stepModelContext = pStepDatabase->getContext(); // Deviation params from properties OdDeviationParams deviationParams(m_properties->getDeviation(), m_properties->getMinPerCircle(), m_properties->getMaxPerCircle()); stepModelContext.setDeviationParams(deviationParams); // Brep params from properties stepModelContext.setBrepParams(OdBrepParams(OdBrepParams::ToleranceType(m_properties->getBrepToleranceType()), m_properties->getBrepToleranceDynamic(), m_properties->getBrepToleranceStatic())); // 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); stepModelContext.setDefaultEntityColor(color); if (OdAPModelContext* pAPModelContext = dynamic_cast(&stepModelContext)) { pAPModelContext->setDrawPlaceholderData(m_properties->getDrawPlaceholderData()); pAPModelContext->setDrawInvisibleObjects(m_properties->getDrawInvisibleObjects()); } // // Get units from STEP model // double addUnitCoefToMeters = 1.; OdTv::Units tvUnits = ::getUnits(pStepDatabase, addUnitCoefToMeters); // // Geometry compose // // timing.startMisc(); // pStepDatabase->setContextSelection(m_selContexts); // stepModelContext.setInterruptCallback((OdDAI::InterruptCallback)m_properties->getInterruptionCallback()); // pStepDatabase->setContext(stepModelContext); // pStepDatabase->composeEntities(); // timing.endMisc(); // composeTiming = timing.getMiscTime(); OdTvStepPartialImportNotifier notifier; OdDbHostAppProgressMeter* pMeter = (OdDbHostAppProgressMeter*)m_properties->getHostAppProgressMeter(); if (pMeter) pMeter->start(OD_T("Import starting...")); notifier.setProgressMeter(pMeter); if (!OdStpXFile::cast(pStepDatabase).isNull()) { //const OdDAI::SetOfOdDAIObjectId* ids = pStepDatabase->getModel()->getEntityExtent("DocumentAssignment"); //if (ids) // notifier.setEntitiesCount(ids->getMemberCount()); //else notifier.setEntitiesCount(0); } else if (!OdCis2File::cast(pStepDatabase).isNull()) { //const OdDAI::SetOfOdDAIObjectId* ids = pStepDatabase->getModel()->getEntityExtent("DocumentAssignment"); //if (ids) // notifier.setEntitiesCount(ids->getMemberCount()); //else notifier.setEntitiesCount(pStepDatabase->getRootIds().size()); } else { int entitiesCount = 0; const OdDAI::SetOfOdDAIObjectId* ids = pStepDatabase->getModel()->getEntityExtent("shape_representation"); if (ids) for (auto it = ids->createConstIterator(); it->next();) { OdDAIObjectId id; if (it->getCurrentMember() >> id) { if (id.getNested()->typeName().compare("shape_representation")) { OdDAI::Aggr* aggr; if (id.openObject()->getAttr("items") >> aggr) entitiesCount += aggr->getMemberCount(); } } } notifier.setEntitiesCount(entitiesCount); } // // Vectorizing // timing.startVectorizing(); OdGsModulePtr pGs = ::odrxDynamicLinker()->loadModule(OdTvVisualizeDeviceModuleName, false); if (!pGs.isNull()) { moduleName = pGs->moduleName(); // // Create vectorizer device // OdGsDevicePtr pDevice = pGs->createDevice(); OdGiContextForStepDatabasePtr giGontextForStepDatabase = OdGiContextForStepDatabase::createObject(); giGontextForStepDatabase->setDatabase(pStepDatabase); giGontextForStepDatabase->enableGsModel(true); OdTvStepGeomertyNotifier geometryNotifier(tvDbId.openObject()); 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("CompareMaterialsForUniquiness"))) pProperties->putAt(OD_T("CompareMaterialsForUniquiness"), 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 // OdGsStepLayoutHelperPtr pLayoutHelper = OdStepGsManager::setupActiveLayoutViews(pDevice.get(), giGontextForStepDatabase); 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)); giGontextForStepDatabase->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("STEPModel")); 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 //OdTvGsViewBackgroundId::BackgroundTypes bgType = m_properties->getUseCustomBgColor() ? OdTvGsViewBackgroundId::kSolid : OdTvGsViewBackgroundId::kGradient; //if (bgType == OdTvGsViewBackgroundId::kSolid) //{ // ODCOLORREF* pBgColor = (ODCOLORREF*)m_properties->getBgColor(); // pTvDevice->setBackgroundColor(*pBgColor); //} //else //{ // OdTvGsViewBackgroundId bkgId = pTvDb->createBackground(OD_T("STEP2VISUALIZE"), bgType); // if (!bkgId.isNull()) // { // if (bgType == OdTvGsViewBackgroundId::kGradient) // { // OdTvGsViewGradientBackgroundPtr pGradientBackground = bkgId.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); // } // else // { // ODA_FAIL_M_ONCE("Step2Visualize background type not implemented"); // } // // pActiveTvView->setBackground(bkgId); // } //} switch (static_cast(m_properties->getCustomBgTypeValue())) { case BackgroundType::kGradient: { OdTvGsViewBackgroundId bgId = pTvDb->createBackground(OD_T("STEP2VISUALIZE"), OdTvGsViewBackgroundId::kGradient); if (!bgId.isNull()) { OdTvGsViewGradientBackgroundPtr pGradientBackground = bgId.openAsGradientBackground(OdTv::kForWrite); pGradientBackground->setColorTop(OdTvColorDef(153, 153, 153)); pGradientBackground->setColorMiddle(OdTvColorDef(184, 184, 184)); pGradientBackground->setColorBottom(OdTvColorDef(216, 216, 216)); 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("Step2Visualize 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.); } } if (m_properties->getNeedCDATree()) { OdPerfTimerBase* pCDATiming = OdPerfTimerBase::createTiming(); pCDATiming->start(); createCommonDataAccessTree(pTvDb, pStepDatabase, fileName + ::getFileExtension(pStepDatabase)); pCDATiming->stop(); CDATiming += pCDATiming->countedSec(); if (pProfileRes) pProfileRes->setCDATreeCreationTime(OdInt64((CDATiming) * 1000.)); OdPerfTimerBase::destroyTiming(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); } if (m_properties->getNeedCDATree()) { OdPerfTimerBase* pCDATiming = OdPerfTimerBase::createTiming(); pCDATiming->start(); createCommonDataAccessTree(pTvDb, pStepDatabase, fileName + ::getFileExtension(pStepDatabase), 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(); } } } //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, pStepDatabase); if (!log.isEmpty()) { OdString logName = (pStepDatabase.isNull() ? fileName : pStepDatabase->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 STEP modules odStepUninitialize(); pRxPropertiesModule = nullptr; // // 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; } //***************************************************************************// // Native properties methods implementation //***************************************************************************// OdTvResult OdTvVisualizeStepFiler::startActionsWithNativeProperties(const OdString& sFilePath, bool bPartial) { if (!m_pStepFile.isNull()) { if (m_pStepFile->getFileName() != sFilePath) m_pStepFile.release(); else return tvOk; } { if (m_pRxPropertiesModule.isNull()) m_pRxPropertiesModule = ::odrxDynamicLinker()->loadModule(L"RxProperties"); } odStepInitialize(true, true); OdTvResult rc = tvOk; if (m_pFilerPtr.isNull()) { m_pFilerPtr = new OdTvVisualizeStepFilerDbSource; } OdStepFilePtr pStepFile = m_pFilerPtr->readFile(sFilePath); if (pStepFile.isNull()) return tvFilerEmptyInternalDatabase; //OdTvVisualizeDwgFilerSourceFromFile dl; //if (!dl.initialize(sFilePath, NULL, &rc)) { try { m_pStepFile = pStepFile; m_pStepModel = m_pStepFile->getModel(); } catch (...) { return tvFilerEmptyInternalDatabase; } } return rc; } bool OdTvVisualizeStepFiler::isActionsWithNativePropertiesStarted(const OdString& sFilePath) { if (!m_pStepFile.isNull() && m_pStepFile->getFileName() == sFilePath) return true; return false; } OdTvResult OdTvVisualizeStepFiler::endActionsWithNativeProperties() { m_pFilerPtr = nullptr; m_pStepModel.release(); m_pStepFile.release(); m_pStepCoreModule.release(); m_pRxPropertiesModule.release(); odStepUninitialize(); ::odrxDynamicLinker()->unloadModule(L"RxProperties"); ::odrxDynamicLinker()->unloadUnreferenced(); return tvOk; } OdRxMemberIteratorPtr OdTvVisualizeStepFiler::getNativePropertiesIterator(OdUInt64 dbHandle, OdTvResult* rc /*= NULL*/) { if (m_pStepModel.isNull()) { if (rc) *rc = tvNativePropMissedDatabase; return OdRxMemberIteratorPtr(); } OdRxMemberIteratorPtr pIter; if (dbHandle == 0) pIter = OdRxMemberQueryEngine::theEngine()->newMemberIterator(m_pStepFile.get()); else { OdDAIObjectId id = m_pStepModel->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 OdTvVisualizeStepFiler::getNativePropertyValue(OdUInt64 dbHandle, const OdRxPropertyPtr& pProperty, bool* bReadOnly /*= NULL*/, OdTvResult* rc /*= NULL*/) { if (pProperty.isNull()) { if (rc) *rc = tvInvalidInput; return OdRxValue(); } if (m_pStepModel.isNull()) { if (rc) *rc = tvNativePropMissedDatabase; return OdRxValue(); } OdRxObjectPtr pInst; if (dbHandle == 0) pInst = m_pStepFile; else { OdDAIObjectId id = m_pStepModel->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 OdTvVisualizeStepFiler::getNativeCollectionPropertyIterator(OdUInt64 dbHandle, const OdRxCollectionPropertyPtr& pCollectionProperty, bool* bReadOnly /*= NULL*/, OdTvResult* rc /*= NULL*/) { return OdRxValueIteratorPtr(); } OdTvResult OdTvVisualizeStepFiler::setNativePropertyValue(OdUInt64 dbHandle, OdRxPropertyPtr& pProperty, const OdRxValue& value) { return tvOk; } OdDbBaseDatabase* OdTvVisualizeStepFiler::getNativeDatabase(OdTvResult* rc /*= nullptr*/) const { if (m_pStepFile.isNull()) { if (rc) { *rc = tvNativePropMissedDatabase; } return nullptr; } return (OdDbBaseDatabase*)m_pStepFile.get(); } //***************************************************************************// // 'OdTvVisualizeStepFilerModule' methods implementation //***************************************************************************// ODRX_DEFINE_DYNAMIC_MODULE(OdTvVisualizeStepFilerModule); void OdTvVisualizeStepFilerModule::initApp() { // Initialize the Visualize SDK odTvInitialize(); // Retrieve a module working dir for host app services schema loading sub-routines OdTvStep2VisService::s_moduleDir = getModuleWorkDir(); } void OdTvVisualizeStepFilerModule::uninitApp() { // Uninitialize the Visualize SDK odTvUninitialize(); } OdString OdTvVisualizeStepFilerModule::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; } OdTvVisualizeFilerPtr OdTvVisualizeStepFilerModule::getVisualizeFiler() const { OdTvVisualizeFilerPtr pDwgFiler = new OdTvVisualizeStepFiler(); return pDwgFiler; } //***************************************************************************// // 'OdTvVisualizeStepFilerDbSource' methods implementation //***************************************************************************// OdStepFilePtr OdTvVisualizeStepFilerDbSource::readFile(const OdString &file) { return m_svcs.readFile(file); } void OdTvStepPartialImportNotifier::entityVectorizationDone(const OdTvEntityId& entityId) { if (entityId.isNull()) return; m_nCurrentObject++; if (m_pMeter) { m_pMeter->meterProgress(); } } void OdTvStepPartialImportNotifier::insertVectorizationDone(const OdTvEntityId& insertId) { m_nCurrentObject++; if (m_pMeter) { m_pMeter->meterProgress(); } } OdTvStepPartialImportNotifier::OdTvStepPartialImportNotifier() { m_nEntitiesEstimation = 0; m_nCurrentObject = 0; m_pMeter = NULL; } OdTvStepPartialImportNotifier::~OdTvStepPartialImportNotifier() { } void OdTvStepPartialImportNotifier::setEntitiesCount(OdUInt32 nCount) { m_nEntitiesEstimation = nCount; if (m_pMeter) m_pMeter->setLimit(m_nEntitiesEstimation); } //***************************************************************************// // OdTvStep2VisService implementation //***************************************************************************// OdAnsiString OdTvStep2VisService::s_moduleDir; #ifdef __APPLE__ #include "CoreFoundation/CoreFoundation.h" OdString getBundlePath() { CFBundleRef bunRef = CFBundleGetMainBundle(); CFURLRef bunUrl = CFBundleCopyBundleURL(bunRef); CFStringRef bunPath = CFURLCopyFileSystemPath(bunUrl, kCFURLPOSIXPathStyle); const char* filePath = CFStringGetCStringPtr(bunPath, kCFStringEncodingUTF8); OdString path = OdString(filePath); // Release references CFRelease(bunPath); CFRelease(bunUrl); CFRelease(bunRef); return path; } #endif OdString OdTvStep2VisService::findFile(const OdString& fileName, OdDbBaseDatabase* pDb, FindFileHint hint) { if (fileName.find(L".exp") >= 0) { #ifdef __APPLE__ OdString schemasFileName = getBundlePath() + OD_T("/Contents/tx/Schemas/") + fileName; #else OdString schemasFileName = OdString(s_moduleDir) + OD_T("Schemas/") + fileName; #endif if (odrxSystemServices()->accessFile(schemasFileName, Oda::kFileRead)) return schemasFileName; } return OdDAIHostAppServicesBase::findFile(fileName, pDb, hint); }