/////////////////////////////////////////////////////////////////////////////// // 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. /////////////////////////////////////////////////////////////////////////////// #ifndef _TV_IGES2VISUALIZE_H_ #define _TV_IGES2VISUALIZE_H_ #include "TD_PackPush.h" #include "RxDispatchImpl.h" #include "RxObject.h" #include "OdFileBuf.h" #include "daiModel.h" #include "ExSystemServices.h" #include "IGES/Core/IgesHostAppServices.h" #include "IGES/Core/IgesInit.h" #include "IGES/Core/IgesFile.h" #include "IGES/Core/IgesGsManager.h" #include "TvVisualizeFiler.h" #include "ExVisualizeDeviceExtensions.h" #include "ThreadsCounter.h" namespace IGES2Visualize { /** \details This class implements the properties of the IGES loader */ class OdTvVisualizeIgesFilerProperties : public OdRxDispatchImpl<> { enum ParamFlags { kObjectNaming = 1, // Give the names for the tv entities according to the file objects name (like AcDbCircle etc). If object names exist kStoreSource = 2, // Store source objects (OdDbEntities) kClearEmptyObjects = 4, // Clear empty objects kRearrangeObjects = 8, // Rearrange objects kNeedCDATree = 16, // Need create CDA tree kNeedCollectPropertiesInCDA = 32, // Need collect native properties in CDA nodes kUseCustomBgColor = 64, // Set custom backround color kIsLogOn = 128, // Enable logging kCalculateIsolines = 256, // Calculate isolines kSurfaceOfRevolutionAsNurbs = 512 // Import Surface of Revolution (Type 120) as NURB Surface }; public: OdTvVisualizeIgesFilerProperties(); virtual ~OdTvVisualizeIgesFilerProperties(); ODRX_DECLARE_DYNAMIC_PROPERTY_MAP(OdTvVisualizeIgesFilerProperties); static OdRxDictionaryPtr createObject(); void setInterruptionCallback(OdIntPtr pInterrupt); OdIntPtr getInterruptionCallback() const; void setDefaultColor(OdIntPtr pDefColor); OdIntPtr getDefaultColor() const; void setBgColor(OdIntPtr pDefColor); OdIntPtr getBgColor() const; void setPalette(OdIntPtr palette); //palette should have 256 colors OdIntPtr getPalette() const; void setDCRect(OdIntPtr rect); //should be pointer to OdTvDCRect OdIntPtr getDCRect() const; void setObjectNaming(bool bSet) { SETBIT(m_flags, kObjectNaming, bSet); } bool getObjectNaming() const { return GETBIT(m_flags, kObjectNaming); } void setStoreSourceObjects(bool bSet) { SETBIT(m_flags, kStoreSource, bSet); } bool getStoreSourceObjects() const { return GETBIT(m_flags, kStoreSource); } void setClearEmptyObjects(bool bSet) { SETBIT(m_flags, kClearEmptyObjects, bSet); } bool getClearEmptyObjects() const { return GETBIT(m_flags, kClearEmptyObjects); } void setRearrangeObjects(bool bSet) { SETBIT(m_flags, kRearrangeObjects, bSet); } bool getRearrangeObjects() const { return GETBIT(m_flags, kRearrangeObjects); } void setNeedCDATree(bool bSet) { SETBIT(m_flags, kNeedCDATree, bSet); } bool getNeedCDATree() const { return GETBIT(m_flags, kNeedCDATree); } void setNeedCollectPropertiesInCDA(bool bSet) { SETBIT(m_flags, kNeedCollectPropertiesInCDA, bSet); } bool getNeedCollectPropertiesInCDA() const { return GETBIT(m_flags, kNeedCollectPropertiesInCDA); } void setUseCustomBgColor(bool bSet) { SETBIT(m_flags, kUseCustomBgColor, bSet); } bool getUseCustomBgColor() const { return GETBIT(m_flags, kUseCustomBgColor); } void setIsLogOn(bool bSet) { SETBIT(m_flags, kIsLogOn, bSet); } bool getIsLogOn() const { return GETBIT(m_flags, kIsLogOn); } void setCalculateIsolines(bool bCalculateIsolines) { SETBIT(m_flags, kCalculateIsolines, bCalculateIsolines); } bool getCalculateIsolines() const { return GETBIT(m_flags, kCalculateIsolines); } void setAppendTransform(OdIntPtr pTransform); OdIntPtr getAppendTransform() const; void setFeedbackForChooseCallback(OdIntPtr pCallback); OdIntPtr getFeedbackForChooseCallback() const; void setDeviation(double deviation); double getDeviation() const; void setMinPerCircle(OdUInt16 minPerCircle); OdUInt16 getMinPerCircle() const; void setMaxPerCircle(OdUInt16 maxPerCircle); OdUInt16 getMaxPerCircle() const; void setModelerType(OdUInt8 type); OdUInt8 getModelerType() const; void setBrepToleranceType(OdUInt8 type); OdUInt8 getBrepToleranceType() const; void setBrepToleranceDynamic(double coef); double getBrepToleranceDynamic() const; void setBrepToleranceStatic(double coef); double getBrepToleranceStatic() const; void setHostAppProgressMeter(OdIntPtr pProgressMeter); OdIntPtr getHostAppProgressMeter() const; void setCustomBgTypeValue(OdInt16 customBgValue); OdInt16 getCustomBgTypeValue() const; void setEnvBackgroundParam(OdIntPtr envParam); OdIntPtr getEnvBackgroundParam() const; void setSurfaceOfRevolutionAsNurbs(bool bSet) { SETBIT(m_flags, kSurfaceOfRevolutionAsNurbs, bSet); } bool getSurfaceOfRevolutionAsNurbs() const { return GETBIT(m_flags, kSurfaceOfRevolutionAsNurbs); } protected: ODCOLORREF m_defaultColor; // Default color which is set to the entity ODCOLORREF m_bgColor; // Background color which is set to the scene const ODCOLORREF* m_pPalette; // Palette to be used. If NULL, one of two default palettes will be used depending on background color. Should have 256 colors OdTvDCRect m_importRect; // Output rectangle. Used for correct import of some specific objects (OLE image, camera). The normal way is to set the output window size OdUInt32 m_flags; // Different options OdTvMatrix m_appendTransform; // Transform for the append OdTvFeedbackForChooseCallback m_pCallback; // Callback for choose OdTvHostAppProgressMeter* m_pHostAppProgressMeter; // host app progress meter OdDAI::InterruptCallback m_pInterruptCallback; // Processes interruption callback OdUInt16 m_customBgTypeValue; OdTvEnvBackgroundImportParameters* m_envBackgroundParam; double m_deviation; OdUInt16 m_minPerCircle; OdUInt16 m_maxPerCircle; OdUInt8 m_modelerType; OdUInt8 m_brepToleranceType; double m_brepToleranceDynamic; double m_brepToleranceStatic; }; typedef OdSmartPtr OdTvVisualizeIgesFilerPropertiesPtr; } class TvRxSystemServicesImpl : public OdRxSystemServices { public: TvRxSystemServicesImpl() {}; OdInt64 getFileCTime(const OdString& filename) { return 0; }; OdInt64 getFileMTime(const OdString& filename) { return 0; }; OdInt64 getFileSize(const OdString& filename) { return 0; }; OdString formatMessage(unsigned int formatId, va_list* argList = 0) { return OD_T(""); }; /** \details Returns the system code page. \remarks On Windows platforms system code page is initialized based on computer's Regional Settings. On other platforms with CP_UNDEFINED. It can be altered by setSystemCodePage() */ OdCodePageId systemCodePage() const { return CP_UNDEFINED; } OdResult getEnvVar(const OdString &varName, OdString &value) { return eNotImplemented; } OdResult setEnvVar(const OdString &varName, const OdString &newValue) { return eNotImplemented; } }; /** \details This class is service for getting database for IGES file */ class OdTvIges2VisService : public OdIgesHostAppServices, public OdDbHostAppProgressMeter, public TvRxSystemServicesImpl { public: static OdAnsiString s_moduleDir; OdTvIges2VisService() : m_pMeter(nullptr) {} void setProgressMeter(OdDbHostAppProgressMeter* pMeter) { m_pMeter = pMeter; } virtual void start(const OdString& displayString = OdString::kEmpty) { if (m_pMeter) m_pMeter->start(displayString); } virtual void stop() { if (m_pMeter) m_pMeter->stop(); } virtual void meterProgress() { if (m_pMeter) m_pMeter->meterProgress(); } virtual void setLimit(int max) { if (m_pMeter) m_pMeter->setLimit(max); } virtual OdDbHostAppProgressMeter* newProgressMeter() { return m_pMeter; } OdString findFile(const OdString& fileName, OdDbBaseDatabase* pDb, FindFileHint hint) override { return OdIgesHostAppServices::findFile(fileName, pDb, hint); } protected: ODRX_USING_HEAP_OPERATORS(TvRxSystemServicesImpl); OdDbHostAppProgressMeter* m_pMeter; }; /** \details This class wraps IGES system services used inside the import process */ class OdTvVisualizeIgesFilerDbSource { protected: OdStaticRxObject m_svcs; public: virtual IgesFilePtr readFile(const OdString &file); }; /** \details This class is IGES loader (to the Visualize database) */ class OdTvVisualizeIgesFiler : public OdTvVisualizeFiler { public: OdTvVisualizeIgesFiler(); virtual OdRxDictionaryPtr properties() { return m_properties; } virtual OdTvDatabaseId loadFrom(const OdString& filePath, OdTvFilerTimeProfiling* pProfileRes = NULL, OdTvResult* rc = NULL) const; virtual OdTvDatabaseId loadFrom(OdStreamBuf* pBuffer, OdTvFilerTimeProfiling* pProfileRes = NULL, OdTvResult* rc = NULL) const; virtual OdTvDatabaseId loadFrom(OdDbBaseDatabase* pDatabase, OdTvFilerTimeProfiling* pProfileRes = NULL, OdTvResult* rc = NULL) const; virtual OdTvDatabaseId generate(OdTvFilerTimeProfiling* pProfileRes = NULL) const; virtual OdTvModelId appendFrom(const OdTvDatabaseId& databaseId, const OdString& filePath, OdTvFilerTimeProfiling* pProfileRes = NULL, OdTvResult* rc = NULL) const; virtual OdTvModelId appendFrom(const OdTvDatabaseId& databaseId, OdStreamBuf* pBuffer, OdTvFilerTimeProfiling* pProfileRes = NULL, OdTvResult* rc = NULL) const; virtual OdTvModelId appendFrom(const OdTvDatabaseId& databaseId, OdDbBaseDatabase* pDatabase, OdTvFilerTimeProfiling* pProfileRes = NULL, OdTvResult* rc = NULL) const; //Native properties support virtual bool hasNativePropertiesSupport() const { return true; } virtual OdTvResult startActionsWithNativeProperties(const OdString& sFilePath, bool bPartial); virtual bool isActionsWithNativePropertiesStarted(const OdString& sFilePath); virtual OdTvResult endActionsWithNativeProperties(); virtual OdRxMemberIteratorPtr getNativePropertiesIterator(OdUInt64 dbHandle, OdTvResult* rc = NULL); virtual OdRxValue getNativePropertyValue(OdUInt64 dbHandle, const OdRxPropertyPtr& pProperty, bool* bReadOnly = NULL, OdTvResult* rc = NULL); virtual OdRxValueIteratorPtr getNativeCollectionPropertyIterator(OdUInt64 dbHandle, const OdRxCollectionPropertyPtr& pCollectionProperty, bool* bReadOnly = NULL, OdTvResult* rc = NULL); virtual OdTvResult setNativePropertyValue(OdUInt64 dbHandle, OdRxPropertyPtr& pProperty, const OdRxValue& value); virtual OdDbBaseDatabase* getNativeDatabase(OdTvResult* rc = NULL) const; int getChoosedRepresentationContexts(IgesFilePtr pIgesFile, OdTvFilerFeedbackForChooseObject & filerFeedbackForChoose, bool& bCanceled) const; OdAnsiString getLog(OdDAI::SessionPtr& pSession, IgesFilePtr pFile) const; protected: mutable OdDAIObjectIds m_selContexts; OdTvModelId import(OdTvDatabaseId &tvDbId, OdStreamBuf* pBuffer, IgesFilePtr pIgesFile, OdTvFilerTimeProfiling* pProfileRes /*= NULL*/, OdTvResult* rc /*= NULL*/) const; private: OdTvGsDeviceId getActiveTvDevice(OdTvDatabaseId& tvDbId, int idDevice) const; int getActiveViewId(OdGsIgesLayoutHelper* pLayoutHelper) const; OdTvGsViewId getActiveTvView(OdTvGsDeviceId& tvDeviceId, int iActViewViewInd) const; OdTvGsViewId getActiveTvView(OdTvDatabaseId& dbId, int iActViewViewInd) const; void createCommonDataAccessTree(OdTvDatabasePtr pTvDb, OdDbBaseDatabase *pDatabase, const OdString& strTreeName, const OdTvModelId& modelId = OdTvModelId()) const; bool processCDANode(OdRxModelTreeBaseNode* pNode, OdRxModelTreeBaseNode* pParentNode) const; OdString getClassNameProperty(const OdArray& nodeProperties) const; int odSelectRepresentationContextsByDefault(OdDAI::ModelPtr pModel) const; private: IGES2Visualize::OdTvVisualizeIgesFilerPropertiesPtr m_properties; IgesFilePtr m_pIgesFile; OdDAI::ModelPtr m_pIgesModel; OdRxModulePtr m_pRxPropertiesModule; OdRxModulePtr m_pIgesCoreModule; OdSharedPtr m_pFilerPtr; }; /** \details This class is IGES loader module implementation */ class OdTvVisualizeIgesFilerModule : public OdTvVisualizeFilerModule { public: virtual OdTvVisualizeFilerPtr getVisualizeFiler() const; OdString getModuleWorkDir() const; void initApp(); void uninitApp(); }; class OdTvIgesPartialImportNotifier : public ExGsVisualizeDeviceNotifier { public: OdTvIgesPartialImportNotifier(); virtual ~OdTvIgesPartialImportNotifier(); // Entities virtual void entityVectorizationDone(const OdTvEntityId& entityId); virtual void insertVectorizationDone(const OdTvEntityId& insertId); virtual void lightVectorizationDone(const OdTvEntityId& lightId) {} virtual void entityRemoved(const OdTvEntityId& entityId) {} virtual void insertRemoved(const OdTvEntityId& insertId) {} virtual void lightRemoved(const OdTvEntityId& insertId) {} // View virtual void viewCreated(const OdTvGsViewId& viewId) {} virtual void viewModified(const OdTvGsViewId& viewId) {} // Table records virtual void layerCreated(const OdTvLayerId& layerId) {} virtual void layerModified(const OdTvLayerId& layerId) {} virtual void materialCreated(const OdTvMaterialId& materialId) {} virtual void imageCreated(const OdTvRasterImageId& iamgeId) {} virtual void blockCreated(const OdTvBlockId& blockId) {} virtual void blockVectorizationBegin(const OdTvBlockId& blockId) {} virtual void blockVectorizationDone(const OdTvBlockId& blockId) {} virtual void linetypeCreated(const OdTvLinetypeId& linetypeId) {} virtual void textStyleCreated(const OdTvTextStyleId& textStyleId) {} // Models virtual void modelCreated(const OdTvModelId& modelId) {} virtual void modelActivated(const OdTvModelId& modelId) {} // Update virtual void updateBegins() {} virtual void updateEnds() {} // Other void setEntitiesCount(OdUInt32 nCount); void setProgressMeter(OdDbHostAppProgressMeter* pMeter) { m_pMeter = pMeter; } protected: OdUInt32 m_nEntitiesEstimation; OdUInt32 m_nCurrentObject; OdDbHostAppProgressMeter* m_pMeter; }; class OdTvIgesGeomertyNotifier : public ExGsVisualizeGeomertyNotifier { public: OdTvIgesGeomertyNotifier(OdTvDatabasePtr tvDatabase) { bool regAlreadyExists; m_regId = tvDatabase->registerAppName(L"#sdai_native_handle", regAlreadyExists); } ~OdTvIgesGeomertyNotifier() {} void onEvent(Event ev, OdTvEntityId topLevelEntityId, OdTvGeometryDataId geometryId) override { TD_AUTOLOCK_P_DEF(m_pMutex); if (topLevelEntityId.getType() == OdTvEntityId::kEntity) { topLevelEntityId.openObject(OdTv::kForWrite)->setNeedCheckShellsTopology(true); } } void onEvent(Event ev, OdTvEntityId topLevelEntityId, OdTvGeometryDataId geometryId, OdGsMarker marker) override { if (marker) { // For IGES format, marker contains just a handle of topological element within an original model. // This handle is assigned to a Visualize SDK object for its associativity with original topological // element, face or edge, of native database. OdTvGeometryDataPtr geometryData = geometryId.openObject(); if (geometryData.isNull() == false) { OdUInt64 qifDatabaseId = static_cast(marker); odSwap8Bytes(&qifDatabaseId); OdTvByteUserData* dataDb = new OdTvByteUserData(&qifDatabaseId, sizeof(OdUInt64), OdTvByteUserData::kCopyOwn, true); geometryData->appendUserData(dataDb, m_regId); } } onEvent(ev, topLevelEntityId, geometryId); } OdUInt32 acceptedEvents() const override { return ExGsVisualizeGeomertyNotifier::kShellAdded; } protected: OdMutexPtr m_pMutex; OdTvRegAppId m_regId; }; #include "TD_PackPop.h" #endif // _TV_IGES2VISUALIZE_H_