3D PLM PPR Hub Open Gateway |
CATIA V5 - ENOVIA VPM V4 Interoperability |
Interactive File Based ImportImplementing the CATIPDMUECreate Interface |
Use Case |
AbstractThis article discusses the CAAPbiUECreate use case which illustrates how to implement the CATIPDMUECreate user exit. The attributes of parts and documents created in CATIA V5 but stored in ENOVIA VPM V4 are provided through this interface. |
This use case is an example of how to implement the CATIPDMUECreate user exit.
[Top]
CAAPbiUECreate is a use case of the CAAPSNInteroperability.edu framework that illustrates the CATIA PDM interoperability features.
[Top]
The goal of CAAPbiUECreate is to provide mandatory attributes of parts and documents when they are created in CATIA V5 but stored in ENOVIA VPM V4. The following methods are called for each parts and documents:
For a part:
For a document:
[Top]
To launch CAAPbiUECreate, please follow these steps:
#CATUEPDMCreate CATIPDMUECreate libCAAPbiUECreate
[Top]
CAAPbiUECreate code is located in the CAAPbiUECreate.m use case module of the CAAPSNInteroperability.edu framework:
InstallRoot/CAACATPBMBaseInterfaces.edu/CAAPbiUECreate.m |
where InstallRoot
is the root directory of your CAA V5
installation. There are two source files named CAAPbiUECreate.cpp and CAAPbiAttributes.cpp
[Top]
[Top]
The purpose of this class is to manipulate the output attributes list. It simplifies the code of the CAAPbiUECreate.cpp.
The constructor stores references to the output arguments (_names, _types, _values and _count) and the maximum attributes count (_maxCount)
CAAPbiAttributes::CAAPbiAttributes(CATListOfCATUnicodeString& inames, CATListOfCATUnicodeString& itypes, void**& ivalues, int& icount, int imaxCount) : _names(inames), // attribute names _types(itypes), // attribute types _values(ivalues), // attribute values _count(icount), // current count _maxCount(imaxCount) // maximum count { // disable adding new attribute until AllocateValues is called _count = _maxCount; } |
The AllocateValues method allocates an array of pointers. Each array position will hold a pointer to an attribute value.
HRESULT CAAPbiAttributes::AllocateValues() { if (NULL == _values) { _values = new void *[_maxCount]; if (NULL == _values) return E_FAIL; else for (int i = 0; i < _maxCount; i++) _values[i] = NULL; } _count = 0; return S_OK; } |
The AddAttribute method updates the output parameters with a new attribute.
void CAAPbiAttributes::AddAttribute(const char *iAttrName, const char *iAttrType, const void *iAttrValue) { if (_count >= _maxCount) return; _names.Append(iAttrName); _types.Append(iAttrType); _values[_count] = (void*) iAttrValue; _count++; } |
[Top]
The implementation is linked to the interface with this code.
#include "TIE_CATIPDMUECreate.h" TIE_CATIPDMUECreate(CAAPbiUECreate); CATImplementClass(CAAPbiUECreate, DataExtension, CATBaseUnknown, CATUEPDMCreate); |
In addition to the code, a dictionary with the following line is required:.
CATUEPDMCreate CATIPDMUECreate libCAAPbiUECreate |
The constructor initializes the cache storage for the environment name and database table name.
CAAPbiUECreate::CAAPbiUECreate(): CATBaseUnknown() { _environment = NULL; _repository = NULL; } |
The destructor frees the cache storage that was allocated
CCAAPbiUECreate::~CAAPbiUECreate() { if (NULL != _environment) { free((void *) _environment); _environment = NULL; } if (NULL != _repository) { free((void *) _repository); _repository = NULL; } } |
GetProductEnvironment for a memory base part returns the part environment name (see GetEnvironment)
HRESULT CAAPbiUECreate::GetProductEnvironment (const CATBaseUnknown* iObj, CATUnicodeString& oEnv, CATUnicodeString& oType) { oEnv = GetEnvironment(); return S_OK; } |
GetProductAttributes for a memory based part returns three attributes:
S_PART_NUMBER and S_TYPE values are obtained differently depending on whether the part is a CATDocument or not.
HRESULT CAAPbiUECreate::GetProductAttributesValue (const CATBaseUnknown* iObj, const CATUnicodeString& iType, int& oNbAttr, CATListOfCATUnicodeString& oAttrName, CATListOfCATUnicodeString& oAttrType, void**& oAttrValues, CATBoolean& oCreateOrUpdate) { if (NULL == iObj) return E_FAIL; oCreateOrUpdate = TRUE; CAAPbiAttributes attrs(oAttrName, oAttrType, oAttrValues, oNbAttr, 3); HRESULT ret = attrs.AllocateValues(); if (FAILED(ret)) return ret; if (iObj->IsAKindOf("CATDocument")) { // // S_PART_NUMBER : "Part"+document name // S_CHG_NUM : 0 // S_TYPE : document extension // CATUnicodeString docName; CATUnicodeString docExt; GetDocNameAndExtension(*(CATDocument*) iObj, docName, docExt); CATUnicodeString partNum("Part"); partNum += docName; const char *cPartNum = CopyUStringToChar(partNum, 32); if (NULL == cPartNum) return E_FAIL; attrs.AddAttribute("S_PART_NUMBER", "String", cPartNum); CATUnicodeString chgNum("0"); const char *cNum = CopyUStringToChar(chgNum, 0); attrs.AddAttribute("S_CHG_NUM", "Integer", num); const char *cPartType = CopyUStringToChar(docExt, 15); if (NULL == cPartType) return E_FAIL; attrs.AddAttribute("S_TYPE", "String", cPartType); } else { // // S_PART_NUMBER : part number // S_CHG_NUM : 0 // S_TYPE : part type // CATUnicodeString partNum; CATIProduct_var prod((CATBaseUnknown*)iObj); if (NULL_var != prod) { partNum = prod->GetPartNumber(); } else { CATISpecObject_var spec((CATBaseUnknown*)iObj); if (NULL_var != spec) { partNum = spec->GetDisplayName(); } } const char *cPartNum = CopyUStringToChar(partNum, 32); if (NULL == cPartNum) return E_FAIL; attrs.AddAttribute("S_PART_NUMBER", "String", cPartNum); CATUnicodeString chgNum("0"); const char *cNum = CopyUStringToChar(chgNum, 0); attrs.AddAttribute("S_CHG_NUM", "Integer", num); CATUnicodeString partType; CATISpecObject_var spec((CATBaseUnknown*)iObj); if (NULL_var != spec) { CATUnicodeString specType= spec->GetType(); specType = specType.Strip(); if (specType == "ASMPRODUCT") partType = "PART"; else if (specType == "DATABASEPRODUCT") partType = "PART"; else partType = specType; } const char *cPartType = CopyUStringToChar(partType, 15); if (NULL == cPartType) return E_FAIL; attrs.AddAttribute("S_TYPE", "String", cPartType); } return S_OK; } |
GetDocumentEnvironment for a memory document returns the environment name (see GetEnvironment) and database table name. The database table name depends on the document type. It is "CATIA_MODEL" for "model"or "CDMAmodel". Otherwise it is "DOCUMENT".
HRESULT CAAPbiUECreate::GetDocumentEnvironment (const CATDocument* iDoc, CATUnicodeString& oEnv, CATUnicodeString& oTable) { oEnv = GetEnvironment(); const char *docNomadType = (NULL != iDoc ? iDoc->IsA() : NULL); oTable = (NULL != docNomadType && strcmp(docNomadType, "model") == 0 || strcmp(docNomadType, "CDMAmodel") == 0 ? "CATIA_MODEL" : "DOCUMENT"); return S_OK; } |
GetDocumentAttributes for a memory based document returns five attributes:
HRESULT CAAPbiUECreate::GetDocumentAttributesValue (const CATDocument* iDoc, int& oNbAttr, CATListOfCATUnicodeString& oAttrName, CATListOfCATUnicodeString& oAttrType, void**& oAttrValues, CATBoolean& oCreateOrUpdate) { if (NULL == iDoc) return E_FAIL; oCreateOrUpdate=TRUE; CAAPbiAttributes attrs(oAttrName, oAttrType, oAttrValues, oNbAttr, 5); HRESULT ret = attrs.AllocateValues(); if (FAILED(ret)) return ret; CATUnicodeString docName; CATUnicodeString docExt; GetDocNameAndExtension(*iDoc, docName, docExt); docName = "CAA" + docName; const char *cDocName = CopyUStringToChar(docName, 12); if (NULL == cDocName) return E_FAIL; attrs.AddAttribute("S_NAME", "String", cDocName); const char *cDocType = CopyUStringToChar(docExt, 8); if (NULL == cDocType) return E_FAIL; attrs.AddAttribute("S_TYPE_REP", "String", cDocType); CATUnicodeString userName("CAA"); const char *cUserName = CopyUStringToChar(userName, 5); if (NULL == cUserName) return E_FAIL; attrs.AddAttribute("S_FORMAT", "String", cUserName); CATUnicodeString repository(GetRepository()); const char *cRepository = CopyUStringToChar(repository, 0); if (NULL == cRepository) return E_FAIL; attrs.AddAttribute("C_LAST_REPOSITORY", "String", cRepository); CATUnicodeString notes("Created from CAA"); const char *cNotes = CopyUStringToChar(notes, 0); if (NULL == cNotes) return E_FAIL; attrs.AddAttribute("NOTES", "String", cNotes); return S_OK; } |
Methods for file based parts and documents are not implemented: they all return E_NOTIMPL:
GetDocumentEnvironment for file based document:
HRESULT CAAPbiUECreate::GetDocumentEnvironment(const char* Filepath, CATUnicodeString& oEnv, CATUnicodeString& oTable) { return E_NOTIMPL; } |
GetDocumentAttribusteValue for file based document
HRESULT CAAPbiUECreate::GetDocumentAttributesValue(const char* iFilepath, int& oNbAttr, CATListOfCATUnicodeString& oAttrName, CATListOfCATUnicodeString& oAttrType, void**& oAttrValues) { return E_NOTIMPL; } |
GetProductAttributesValue for file base part:
HHRESULT CAAPbiUECreate::GetProductAttributesValue(const char* iFilepath, int& oNbAttr, CATListOfCATUnicodeString& oAttrName, CATListOfCATUnicodeString& oAttrType, void**& oAttrValues) { return E_NOTIMPL; } |
GetEnvironment returns the value of the environment variable CV5_VPM_ENV or "VPMENV" if it is not defined. This result is cached to avoid computation during subsequent calls.
const char *CAAPbiUECreate::GetEnvironment() { static const char *env = NULL; if (NULL == env) { if (CATGetEnvValue("CV5_VPM_ENV", (char **) &_environment) == CATLibSuccess) { env = _environment; } else { env = "VPMENV"; } } return env; } |
Similar to GetEnvironment, GetRepository returns the value of the environment variable CV5_VPM_REPOSITORY or "DBLFAIX.BIN PATH $HOME/db/" if it is undefined. The result is also cached.
const char *CAAPbiUECreate::GetRepository() { static const char *rep = NULL; if (NULL == rep) { if (CATGetEnvValue("CV5_VPM_REPOSITORY", (char **) &_repository) == CATLibSuccess) { rep = _repository; } else { rep = "DBLFAIX.BIN PATH $HOME/db/"; } } return rep; } |
GetDocNameAndExtension returns the storage path of a memory based CATDocument: split into two parts: the file name and the file extension.
void CAAPbiUECreate::GetDocNameAndExtension (const CATDocument& iDoc, CATUnicodeString& ioDocName, CATUnicodeString& ioDocExt) { CATUnicodeString docStorageName = iDoc.StorageName(); char docDir[CATMaxPathSize]; char docFileName[CATMaxPathSize]; CATSplitPath(docStorageName.ConvertToChar(), docDir, docFileName); char *dotpos = strrchr(docFileName, '.'); if (NULL != dotpos) { *dotpos = 0; ioDocName = docFileName; dotpos++; ioDocExt = dotpos; } else { ioDocName = docFileName; ioDocExt = ""; } } |
CopyUStringToChar converts a CATUnicodeString to an ASCII string of a given size. The resulting string is truncated or padded with spaces as necessary.
const char *CAAPbiUECreate::CopyUStringToChar (CATUnicodeString& iStr, int iSize) { int len; if (0 == iSize) { // length is null, copy whole string len = iStr.GetLengthInChar(); } else { // only copy up to specified length // padding with spaces if necessary iStr.Resize(iSize); len = iSize; } char *ptr = new char [len + 1]; if (NULL == ptr) return NULL; strcpy(ptr, iStr.ConvertToChar()); return ptr; } |
This use case has demonstrated how to implement the CATIPDMUECreate interface.
[Top]
Version: 1.2 [Oct 2005] | Document revised |
Version: 1.1 [Sep 2003] | Document revised |
Version: 1 [Jul 2003] | Document created |
[Top] |
Copyright © 2003, Dassault Systèmes. All rights reserved.