Mechanical Design |
Structure |
Retrieving the Structure Section Document ParametersHow to retrieve the structure section document parameters as computed attributes |
Use Case |
AbstractThis article discusses the CAAStrRetrieveSectionParameter use case. |
This use case is intended to show you how to initialize CATIA session, get the root product and query the structure member section, and retrieve the section parameters as the computed attributes on the member objects.
[Top]
CAAStrRetrieveSectionParameter is a use case of the CAAStructureInterfaces.edu framework that illustrates StructureInterfaces framework capabilities.
[Top]
The goal of CAAStrRetrieveSectionParameter is to show you how to use the StructureInterfaces methods to query and obtain structure section document. Defining the computed (non-persistent, run time) attribute on the profiles, then implementing the GetValue on the CATIPspKweUserAttr interface to display the internal section parameters as the profile attributes.
[Top]
To launch CAAStrRetrieveSectionParameter, you will need to set up the build time environment, then compile CAAStrRetrieveSectionParameter along with its prerequisites, set up the run time environment, and then execute the sample. This is fully described in the referenced article [1]. When launching the use case, you must pass the following arguments:
[Top]
CAAStrRetrieveSectionParameter code is located in the CAAStrUserProperties.m use case module of the CAAStructureInterfaces.edu framework:
Windows | InstallRootDirectory\CAAStructureInterfaces.edu\ CAAStrUserProperties.m |
Unix | InstallRootDirectory/CAAStructureInterfaces.edu/ CAAStrUserProperties.m |
[Top]
CAAStrDefineUserProperties code is located in the CAAStrDefineUserProperties.m use case module of the CAAStructureInterfaces.edu framework: This code illustrates how to define the computed attribute on the profile object, and implement the GetValue method to valuate the added attribute.
Windows | InstallRootDirectory\CAAStructureInterfaces.edu\ CAAStrDefineUserProperties.m |
Unix | InstallRootDirectory/CAAStructureInterfaces.edu/ CAAStrDefineUserProperties.m |
where InstallRootDirectory
is the root directory of your CAA V5
installation. It is made of one unique source files named
CAAStrRetrieveSectionParameter.cpp.
[Top]
There are seven logical steps in CAAStrRetrieveSectionParameter :
[Top]
In this use case, we open an input document containing some Structure objects.
[Top]
The CAAStrRetrieveSectionParameter is a standalone batch program . The initialization of the CATIA session and retrieving pointer of the root product involves the following code
CATSession* pSession = NULL; rc = ::Create_Session("CAA2_Sample_Session",pSession); if (SUCCEEDED(rc)) cout << endl << " ## CAAStrRetrieveSectionParameter ## " << endl << endl << " Initialize CATIA Session Succeeded " << endl << flush; cout << endl << " Input document path " << argv[1] << endl << flush; CATDocument* pDoc = NULL; rc = CATDocumentServices::OpenDocument(argv[1],pDoc); if ( FAILED(rc) || (NULL==pDoc)) return 2; cout << endl << " product document opened : " << argv[1] << endl << flush; |
This code performs the following functions:
[Top]
Implement the CATIPspKweUserAttr interface.To define the attribute on an existing object, user needs to implement the DefineKweUserAttr method. In this method program can add any attribute type to the input object. To valuate the added attribute type, user needs to implement the GetValue method. In this method program can valuate the attribute value.
HRESULT CAAStrDefineUserAttributes::DefineKweUserAttr(const CATString &isTypeName, CATListValCATAttributeInfos &olAttrInfos) { HRESULT rc = E_FAIL; // // To activate this implementation remove the following "if" conditional block. // if (CATGetEnvValue("RunSample",0) != CATLibSuccess) { return rc; } CATTry { CATITypeDictionary_var spDico = CATGlobalFunctions::GetTypeDictionary(); // Get Dictionary of types CATIParmDictionary_var spParmDictionary = CATCkeGlobalFunctions::GetParmDictionary(); if(!!spDico && !!spParmDictionary) { if( isTypeName == "CATSfmStiffenerExt" || isTypeName == "CATSfmBeamExt" || isTypeName == "CATSfmStiffenerOnFreeEdgeExt") { cout<<"Defining computed attribute for " << isTypeName.CastToCharPtr() << endl; // // Define Real type computed attribute SectionArea // CATUnicodeString uAttrInternalName(USER_ATTR_SectionArea); CATUnicodeString uAttrNLSName(USER_ATTR_SectionArea_NLS); CATICkeType_var spCkeReal = spParmDictionary->GetRealType(); CATIType_var spTypeReal(spCkeReal); CATAttributeInfos infoAttr(spTypeReal, uAttrInternalName, uAttrNLSName); olAttrInfos.Append(infoAttr); } rc = S_OK; } } CATCatch (CATError, error) { cout << "CAAStrDefineUserAttributes::DefineKweUserAttr *** CATRethrow" << endl; CATRethrow; } CATEndTry; return rc; } CATIValue* CAAStrDefineUserAttributes::GetValue (CATIInstance* ipiObject, const CATUnicodeString& iKey) { HRESULT rc = E_FAIL; CATIValue * piResultValue = NULL; // // To active this implementation remove the following condition // if (CATGetEnvValue("RunSample",0) != CATLibSuccess) { return piResultValue; } if( NULL == ipiObject) return piResultValue; // Get volatile factory of values CATICkeParmFactory_var spVolFactory = CATCkeGlobalFunctions::GetVolatileFactory(); CATTry { CATUnicodeString uAttrInternalName(USER_ATTR_SectionArea); if (iKey == uAttrInternalName) { CATIStructureMember *piStrMember = NULL; ipiObject->QueryInterface(IID_CATIStructureMember, (void **)&piStrMember); if ( NULL != piStrMember) { CATLISTV(CATISpecObject_var) oListParameters; CATISpecObject_var spSpecObjectPart; CATDocument *piSectionDoc = NULL; piStrMember->GetSection(piSectionDoc); if (piSectionDoc) { CATInit *pInitOnDoc = NULL ; if (SUCCEEDED(piSectionDoc->QueryInterface(IID_CATInit,(void **) &pInitOnDoc)) && pInitOnDoc) { CATIPrtContainer *pIPrtCont = NULL ; pIPrtCont = (CATIPrtContainer*)pInitOnDoc->GetRootContainer("CATIPrtContainer"); if (pIPrtCont) { spSpecObjectPart = pIPrtCont->GetPart(); pIPrtCont->Release(); pIPrtCont = NULL; } pInitOnDoc->Release(); pInitOnDoc = NULL; } } // Get all the parameters under the part CATIParmPublisher_var spParmPub(spSpecObjectPart); if (!! spParmPub) { spParmPub->GetAllChildren("CATICkeParm",oListParameters); } double SectionArea = 0.; CATICkeParm_var spResultParm; // Get the Section Area from Parameter "A" int lSize = oListParameters.Size(); for (int i=1; i <= lSize; i++) { CATICkeParm_var spCkeParm(oListParameters[i]); cout << " Parameter name " << (spCkeParm->Name()).ConvertToChar() << endl; cout << " Parameter Role " << (spCkeParm->Role()).ConvertToChar() << endl; cout << " Parameter value " << (spCkeParm->Show()).ConvertToChar() << endl; if (!! spCkeParm ) { CATUnicodeString SectionParameterArea("A"); CATUnicodeString ParameterRole = (spCkeParm->Role()).Strip(CATUnicodeString::CATStripModeBoth); if (ParameterRole == SectionParameterArea ) { SectionArea = (spCkeParm->Value())->AsReal(); break; } } } if (!!spVolFactory) { CATUnicodeString iUnit = "AREA"; CATIParmDictionary_var spParmDictionary = CATCkeGlobalFunctions::GetParmDictionary(); if (!! spParmDictionary) { CATICkeMagnitude_var spMagnitude = spParmDictionary->FindMagnitude(iUnit); spResultParm = spVolFactory->CreateDimension(spMagnitude,iKey,SectionArea); } } if (!! spResultParm) { spResultParm->Valuate(SectionArea); spResultParm->QueryInterface(IID_CATIValue, (void **)&piResultValue); } piStrMember->Release(); piStrMember = NULL; } } } CATCatch (CATError, error) { cout << "CAAStrDefineUserAttributes::GetValue *** CATRethrow" << endl; CATRethrow; } CATEndTry; if (piResultValue) { cout << "Returning value: " << (piResultValue->Show()).ConvertToChar() << endl; } return piResultValue; } |
[Top]
Retrieves all the structure member object under the current part document
CATIDescendants_var spPartAsDesc = spSpecObjectPart; CATLISTV(CATISpecObject_var) ListMember; if (!! spPartAsDesc) spPartAsDesc->GetAllChildren("CATIStructureMember", ListMember); /* ------------------------------------------- */ /* 4. Access member's section area attribute */ /* ------------------------------------------- */ int numberOfChildren = ListMember.Size(); cout << endl << " The number of Children for CATIStructureMember " << numberOfChildren << endl << flush; for (int i = 1; i <= numberOfChildren; i++) { rc = AccessMemberSectionAttribute( (ListMember)[i]); if (!SUCCEEDED(rc)) return 5; } |
[Top]
To retrieve the section document parameters through the GetValue method which
implemented at CAAStrDefineUserProperties.m
.
CATIValue* piVal = NULL; if ( NULL_var != ispMember ) { CATIAlias_var spAlias(ispMember); if (!! spAlias) cout << "Member " << (spAlias->GetAlias()).ConvertToChar() << endl; CATIInstance *piInstance = NULL; rc = ispMember->QueryInterface (IID_CATIInstance,(void **)&piInstance); if( SUCCEEDED(rc) && piInstance) { piVal = piInstance->GetValue("SectionArea"); if( NULL != piVal ) { CATUnicodeString uAttrVal = piVal->Show(); cout << "SectionArea value is: " << uAttrVal.ConvertToChar() << endl; } piInstance->Release(); piInstance = NULL; } } if ( NULL != piVal ) { piVal->Release(); piVal = NULL; } |
[Top]
Never forget to delete a created session and removes the opened documents after the usage .
/* -------------------------------------------- */ /* Ends the session */ /* -------------------------------------------- */ // remove opened document rc = CATDocumentServices::Remove (*pDoc); if (!SUCCEEDED(rc)) return 6; rc = ::Delete_Session("CAA2_Sample_Session"); if (SUCCEEDED(rc)) cout << " Delete Session Succeeded " << endl << flush; |
[Top]
This use case has demonstrated how to use the Structure interfaces and CATIPspKweUserAttr to query section document parameters as computed attribute on the structure member objects. Specifically, it has illustrated:
[Top]
[1] | Building and Launching a CAA V5 Use Case |
Version: 1 [June 2006] | Document created |
[Top] |
Copyright © 2003, Dassault Systèmes. All rights reserved.