Equipment & Systems |
Distributive Systems |
Adding a Design Validation CheckHow to add a design validation check. |
Use Case |
AbstractThis article discusses the CAADVTubeAttributes use case. |
This use case is intended to show you how to add a design check to the design validation process.
[Top]
CAADVTubeAttributes is a use case of the CAAPlantShipInterfaces.edu framework that illustrates CATPlantShipInterfaces framework capabilities.
[Top]
CAADVTubeAttributes checks tube size and material to see if they are authorized. CATPlantShipInterfaces methods are used to test that a product is a tube, to retrieve the tubing line, to read attributes from the tube and its tubing line and to test those attributes against design criteria.
[Top]
To use CAADVTubeAttributes, you will need to set up the build time environment, then compile CAADVTubeAttributes along with its prerequisites, set up the run time environment. This is fully described in the referenced article [1]. You then execute CATIA and use the Design Validation command.
[Top]
CAADVTubeAttributes code is consists of four files located in the CAAPspDesignValidation.m use case module of the CAAPlantShipInterfaces.edu framework:
Windows |
InstallRootDirectory\CAAPlantShipInterfaces.edu\CAAPspDesignValidation.m\LocalInterfaces\CAADVTubeAttributes.h InstallRootDirectory\CAAPlantShipInterfaces.edu\CAAPspDesignValidation.m\LocalInterfaces\CAAViolationTubeAttributes.h InstallRootDirectory\CAAPlantShipInterfaces.edu\CAAPspDesignValidation.m\src\CAADVTubeAttributes.cpp InstallRootDirectory\CAAPlantShipInterfaces.edu\CAAPspDesignValidation.m\src\CAAViolationTubeAttributes.cpp InstallRootDirectory\CAAPlantShipInterfaces.edu\CNext\code\dictionary\CAAPlantShipInterfaces.edu.dico InstallRootDirectory\CAAPlantShipInterfaces.edu\CNext\resources\msgcatalog\CAAPspDesignValidation.CATNls |
Unix |
InstallRootDirectory/CAAPlantShipInterfaces.edu/CAAPspDesignValidation.m/LocalInterfaces/CAADVTubeAttributes.h InstallRootDirectory/CAAPlantShipInterfaces.edu/CAAPspDesignValidation.m/LocalInterfaces/CAAViolationTubeAttributes.h InstallRootDirectory/CAAPlantShipInterfaces.edu/CAAPspDesignValidation.m/src/CAADVTubeAttributes.cpp InstallRootDirectory/CAAPlantShipInterfaces.edu/CAAPspDesignValidation.m/src/CAAViolationTubeAttributes.cpp InstallRootDirectory/CAAPlantShipInterfaces.edu/CNext/code/dictionary/CAAPlantShipInterfaces.edu.dico InstallRootDirectory/CAAPlantShipInterfaces.edu/CNext/resources/msgcatalog/CAAPspDesignValidation.CATNls |
where InstallRootDirectory
is the root directory of your CAA V5
installation.
This sample uses two C++ source files: CAADVTubeAttributes.cpp and CAAViolationTubeAttributes.cpp. CAADVTubeAttributes.cpp defines the validation check. CAAViolationTubeAttributes.cpp defines the violation that is created when the validation check fails. Each source file has a corresponding header (.h) file. There are also two supporting data files CAAPlantShipInterfaces.edu.dico and CAAPspDesignValidation.CATNls.
[Top]
CAADVTubeAttributes and CAAViolationTubeAttributes are classes that that provide information to the Design Validation command. The remainder of this document describes the various parts of these classes.
[Top]
CAADVTubeAttributes header is mostly explanatory comments and necessary include files. It also contains the class contructors. Take special note of the CATImplementClass macro. This macro defines the class as implementing a CAA interface. It is very important to properly code this macro so that CATIA will recognize the implementation. CATImplementClass has four arguments. The first is the name of the class itself, CAADVTubeAttributes. The second, CodeExtension, defines this class as only extending code. It stores no data. The third, CATEAPspDesignValidation, is the base class of this implementation. All design check classes should be based on CATEAPspDesignValidation. Finally CAATubAttr defines the type of object this class is an implementation. CATIA will call this class when the CATIPspDesignValidation interface is called on a CAATubAttr object. A different object type should be used for each new design check implementation. Immediately after CATImplementClass are the statements that tie CAADVTubeAttributes to CATIPspDesignValidation.
The method GetValidationChecks is also in the header. GetValidationChecks is part of the CATIPspDesignValidation interface. It is necessary to define the validation checks this class performs. From it you can see that CAADVTubeAttributes performs the "TubeSize" and "TubeMaterial" checks.
/** * @quickreview eml 07:04:25 Replace tabs with spaces. * @fullreview eml svo 07:04:24 Creation */ //============================================================================= // COPYRIGHT DASSAULT SYSTEMES 2007 //============================================================================= // // Component Identifier: CAADVTubeAttributes.cpp // //============================================================================= // // Implementation Notes: // // This checks tube attributes. // Input attributes: // Operating Pressure (from line) // Nominal Size // Material Category // // Output attributes: // Allowed nominal sizes. // Allowed material. // // Violation Object ---> CATCloViolation_Atr // // // HRESULT return has the following meaning: // // CATReturnSuccess (S_OK) ...... Design violation detected & Violation object created // S_FALSE ... No violation found (or Check not applicable) // CATReturnFailure (E_FAIL) .... Violation check not performed due to invalid input/errors // // //============================================================================= // // Creation: 2007 April 23 Eric Miller // //============================================================================= #include "CAADVTubeAttributes.h" #include "CAAViolationTubeAttributes.h" #include "CATError.h" #include "CATErrorMacros.h" #include "CATEsuDeletionMacro.h" #include "CATIPspAttribute.h" #include "CATIPspGroupable.h" #include "CATIPspLogicalLine.h" #include "CATIPspObject.h" #include "CATICkeParm.h" #include "IUnknown.h" #include "CATIUnknownList.h" #include "CATObject.h" #include "CATISpecObject.h" #include "CATUnicodeString.h" CATImplementClass( CAADVTubeAttributes, CodeExtension, CATEAPspDesignValidation, // adaptor CAATubAttr ); #include <TIE_CATIPspDesignValidation.h> TIE_CATIPspDesignValidation(CAADVTubeAttributes); //----------------------------------------------------------------------------- // Constructor //----------------------------------------------------------------------------- CAADVTubeAttributes::CAADVTubeAttributes():CATEAPspDesignValidation () {} //----------------------------------------------------------------------------- // Destructor //----------------------------------------------------------------------------- CAADVTubeAttributes::~CAADVTubeAttributes() {} //----------------------------------------------------------------------------- // CATIPspDesignValidation methods //----------------------------------------------------------------------------- HRESULT CAADVTubeAttributes::GetValidationChecks( CATListValCATUnicodeString& oChecks ) { oChecks.RemoveAll(); oChecks.Append( "TubeSize" ); oChecks.Append( "TubeMaterial" ); return CATReturnSuccess; } .... .... |
[Top]
CAADVTubeAttributes uses three methods to perform its checks. The primary method is IsObjectAViolation which is required by the CATIPspDesignValidation interface. IsObjectAViolation determines which checks need to be performed and calls methods to do appropriate checks. It passes any found violations back in the oViolation list. IsObjectAViolation performs two checks, "TubeSize" and "TubeMaterial." "TubeSize" and "TubeMaterial" are also keys to the natural language file (NLS). It calls CheckTubeSize to check for an authorized tube size. It calls CheckTubeMaterial to check for an authorized tube material for the given size. CheckTubeSize and CheckTubeMaterial are very similar. Both gather background class data (classification, validation type and resource) needed for the check. They then make sure the input object is a tube and get its tubing line. After that they get needed attribute parameters and data from the parameters. The parameters used in this simple example are operating pressure from the tubing line and nominal size and material from the tube. Finally they test for a violation and return a violation in the list if one is found. CheckTubeSize tests for a size violation and reports a "TubeSize" violation if found. CheckTubeMaterial tests for a material violation and reports a "TubeMaterial" violation if found.
.... .... //----------------------------------------------------------------------------- HRESULT CAADVTubeAttributes::IsObjectAViolation( const CATBaseUnknown* iObject, const CATListValCATUnicodeString& iChecks, CATListPV** oViolation, const unsigned int& iErrorFile ) { HRESULT returnCode = CATReturnFailure; *oViolation = NULL; //-------------------------------------------------------------------------- // Declare variables here to avoid memory leaks from thrown errors //-------------------------------------------------------------------------- // Variables that need release handling. // Variables that do not need release handling. int numChecks = 0; CATTry { // Determine which checks were requested int numChecks = iChecks.Size(); if (iObject && 0 <= numChecks) { returnCode = S_FALSE; // Input OK, now most failure because test not applicable. if ( SUCCEEDED(returnCode) && iChecks.Locate ("TubeSize") > 0 ) { HRESULT rcCheck = CheckTubeSize(iObject, oViolation, iErrorFile); if (S_FALSE != rcCheck) returnCode = rcCheck; } if ( SUCCEEDED(returnCode) && iChecks.Locate ("TubeMaterial") > 0 ) { HRESULT rcCheck = CheckTubeMaterial(iObject, oViolation, iErrorFile); if (S_FALSE != rcCheck) returnCode = rcCheck; } } // End if valid input. } // End CATTry CATCatch( CATError, pError ) { returnCode = CATReturnError(pError); } CATEndTry; // Release memory return returnCode; } .... .... //----------------------------------------------------------------------------- HRESULT CAADVTubeAttributes::CheckTubeSize(const CATBaseUnknown* iObject, CATListPV** oViolation, const unsigned int& iErrorFile) { HRESULT returnCode = CATReturnFailure; //-------------------------------------------------------------------------- // Declare variables here to avoid memory leaks from thrown errors //-------------------------------------------------------------------------- // Variables that need release handling. CATISpecObject* piObjectSpec = NULL; CATIPspLogicalLine *piLogicalLine = NULL; CATIPspAttribute* piAttr = NULL; CATICkeParm *piPressureParm = NULL; CATICkeParm *piNominalSizeParm = NULL; CATICkeParm *piMaterialParm = NULL; CAAViolationTubeAttributes *pViolation = NULL; // Variables that do not need release handling. HRESULT rcInternal = CATReturnSuccess; CATUnicodeString uClassification; CATUnicodeString uValidationType; CATUnicodeString uNLSResource; CATUnicodeString uPartType; CATUnicodeString uPartName; double pressure = 0.0; CATUnicodeString uPressure; CATUnicodeString uNominalSize; CATUnicodeString uMaterial; CATUnicodeString uAuthorizedSizes; CATTry { // Get classification GetClassification (uClassification); // Get validation type GetType (uValidationType); // Get resource for NLS. GetResource (uNLSResource); if (iObject && !uClassification.IsNull() && !uValidationType.IsNull() && !uNLSResource.IsNull()) { returnCode = S_FALSE; // Input OK, now most failure because test not applicable. // Get spec object. if (SUCCEEDED(((CATBaseUnknown*)iObject)->QueryInterface(IID_CATISpecObject,(void**)&piObjectSpec)) && piObjectSpec) { uPartType = piObjectSpec->GetType (); uPartName = piObjectSpec->GetName (); // Test that object is a tube. if (piObjectSpec->IsSubTypeOf("CATTubStraightTube") || piObjectSpec->IsSubTypeOf("CATTubBendableTube")) { if (SUCCEEDED(rcInternal = GetLogicalLine(piObjectSpec, piLogicalLine))) { // Get attributes needed for calculation. if (SUCCEEDED(rcInternal = GetObjectAttribute(piLogicalLine, "Operating pressure", piPressureParm)) && SUCCEEDED(rcInternal = GetObjectAttribute(piObjectSpec, "Nominal size", piNominalSizeParm)) && SUCCEEDED(rcInternal = GetObjectAttribute(piObjectSpec, "MaterialCategory", piMaterialParm))) { // Get test data. rcInternal = GetTestData(piPressureParm, piNominalSizeParm, piMaterialParm, pressure, uPressure, uNominalSize, uMaterial); if (SUCCEEDED(rcInternal)) { // Test nominal size against rules. rcInternal = TestTubeSize(pressure, uNominalSize, uAuthorizedSizes); if (CATReturnSuccess == rcInternal) { // Have a violation pViolation = new CAAViolationTubeAttributes (uValidationType, "TubeSize", uNLSResource); if (pViolation) { // Set violation info. pViolation->SetInfo(uPressure, uNominalSize, uMaterial, uAuthorizedSizes); // Add violation to output list. AddViolation (oViolation, pViolation); } // End if valid violation pointer. } // End if violation returned. } // End if succeeded getting test data. } // End if valid attributes. } // End if valid logical line. } // End if tube. } // End if valid spec object. } // End if valid input and supporting data. } // End CATTry CATCatch( CATError, pError ) { rcInternal = CATReturnError(pError); } CATEndTry; // Release memory CATEsuDeleteBaseUnknown(piObjectSpec); CATEsuDeleteBaseUnknown(piLogicalLine); CATEsuDeleteBaseUnknown(piAttr); CATEsuDeleteBaseUnknown(piPressureParm); CATEsuDeleteBaseUnknown(piNominalSizeParm); CATEsuDeleteBaseUnknown(piMaterialParm); if (FAILED(rcInternal)) { returnCode = rcInternal; } else if (oViolation && *oViolation) { returnCode = CATReturnSuccess; } return returnCode; } //----------------------------------------------------------------------------- HRESULT CAADVTubeAttributes::CheckTubeMaterial(const CATBaseUnknown* iObject, CATListPV** oViolation, const unsigned int& iErrorFile) { HRESULT returnCode = CATReturnFailure; //-------------------------------------------------------------------------- // Declare variables here to avoid memory leaks from thrown errors //-------------------------------------------------------------------------- // Variables that need release handling. CATISpecObject* piObjectSpec = NULL; CATIPspLogicalLine *piLogicalLine = NULL; CATIPspAttribute* piAttr = NULL; CATICkeParm *piPressureParm = NULL; CATICkeParm *piNominalSizeParm = NULL; CATICkeParm *piMaterialParm = NULL; CAAViolationTubeAttributes *pViolation = NULL; // Variables that do not need release handling. HRESULT rcInternal = CATReturnSuccess; CATUnicodeString uClassification; CATUnicodeString uValidationType; CATUnicodeString uNLSResource; CATUnicodeString uPartType; CATUnicodeString uPartName; double pressure = 0.0; CATUnicodeString uPressure; CATUnicodeString uNominalSize; CATUnicodeString uMaterial; CATUnicodeString uAuthorizedMaterialForSize; CATTry { // Get classification GetClassification (uClassification); // Get validation type GetType (uValidationType); // Get resource for NLS. GetResource (uNLSResource); if (iObject && !uClassification.IsNull() && !uValidationType.IsNull() && !uNLSResource.IsNull()) { returnCode = S_FALSE; // Input OK, now most failure because test not applicable. // Get spec object. if (SUCCEEDED(((CATBaseUnknown*)iObject)->QueryInterface(IID_CATISpecObject,(void**)&piObjectSpec)) && piObjectSpec) { uPartType = piObjectSpec->GetType (); uPartName = piObjectSpec->GetName (); // Test that object is a tube. if (piObjectSpec->IsSubTypeOf("CATTubStraightTube") || piObjectSpec->IsSubTypeOf("CATTubBendableTube")) { if (SUCCEEDED(rcInternal = GetLogicalLine(piObjectSpec, piLogicalLine))) { // Get attributes needed for calculation. if (SUCCEEDED(rcInternal = GetObjectAttribute(piLogicalLine, "Operating pressure", piPressureParm)) && SUCCEEDED(rcInternal = GetObjectAttribute(piObjectSpec, "Nominal size", piNominalSizeParm)) && SUCCEEDED(rcInternal = GetObjectAttribute(piObjectSpec, "MaterialCategory", piMaterialParm))) { // Get test data. rcInternal = GetTestData(piPressureParm, piNominalSizeParm, piMaterialParm, pressure, uPressure, uNominalSize, uMaterial); if (SUCCEEDED(rcInternal)) { // Test nominal size against rules. rcInternal = TestTubeMaterial(pressure, uNominalSize, uMaterial, uAuthorizedMaterialForSize); if (CATReturnSuccess == rcInternal) { // Have a violation pViolation = new CAAViolationTubeAttributes (uValidationType, "TubeMaterial", uNLSResource); if (pViolation) { // Set violation info. pViolation->SetInfo(uPressure, uNominalSize, uMaterial, uAuthorizedMaterialForSize); // Add violation to output list. AddViolation (oViolation, pViolation); } // End if valid violation pointer. } // End if violation returned. } // End if succeeded getting test data. } // End if valid attributes. } // End if valid logical line. } // End if tube. } // End if valid spec object. } // End if valid input and supporting data. } // End CATTry CATCatch( CATError, pError ) { rcInternal = CATReturnError(pError); } CATEndTry; // Release memory CATEsuDeleteBaseUnknown(piObjectSpec); CATEsuDeleteBaseUnknown(piLogicalLine); CATEsuDeleteBaseUnknown(piAttr); CATEsuDeleteBaseUnknown(piPressureParm); CATEsuDeleteBaseUnknown(piNominalSizeParm); CATEsuDeleteBaseUnknown(piMaterialParm); if (FAILED(rcInternal)) { returnCode = rcInternal; } else if (oViolation && *oViolation) { returnCode = CATReturnSuccess; } return returnCode; } .... .... |
[Top]
CAADVTubeAttributes has three methods which get background data. These methods are overridden from its base class, CATEAPspDesignValidation. GetClassification provides the classification type which in this case is Validation_Object. It indicates that CAADVTubeAttributes processes single objects. GetResource gives the resource (file) that contains NLS information and is described below. GetColumnTitles gives the names of the data columns used in the violation report. TubeAttributeColPressure, TubeAttributeColSize, TubeAttributeColMaterial and TubeAttributeColAuthorized are keys in the NLS file.
.... .... //----------------------------------------------------------------------------- // CATEAPspDesignValidation methods //----------------------------------------------------------------------------- HRESULT CAADVTubeAttributes::GetClassification( CATUnicodeString& oClassification ) { oClassification = Validation_Object; return CATReturnSuccess; } HRESULT CAADVTubeAttributes::GetResource( CATUnicodeString& oName ) { oName = "CAAPspDesignValidation"; return CATReturnSuccess; } //----------------------------------------------------------------------------- HRESULT CAADVTubeAttributes::GetColumnTitles( CATListValCATUnicodeString& oTitles ) { HRESULT returnCode = CATReturnFailure; oTitles.RemoveAll(); CATListValCATUnicodeString column; // From CAAPspDesignValidation.CATNls file column.Append( "TubeAttributeColPressure" ); column.Append( "TubeAttributeColSize" ); column.Append( "TubeAttributeColMaterial" ); column.Append( "TubeAttributeColAuthorized" ); if ( GetDescriptions( column, oTitles ) ) returnCode = CATReturnSuccess; return returnCode; } .... .... |
[Top]
CAADVTubeAttributes has three routines which support attribute data gathering. GetLogicalLine get the tubing line (generically called a logical line) for a tube. GetObjectAttribute gets an attribute associated with an object and returns it as a knowledgeware parameter. GetTestData extracts needed operating pressure, nominal size and material from its input parameters.
.... .... //----------------------------------------------------------------------------- HRESULT CAADVTubeAttributes::GetLogicalLine(const IUnknown *ipiLogicalLineMember, CATIPspLogicalLine *&opiLogicalLine) { HRESULT returnCode = CATReturnFailure; opiLogicalLine = NULL; // Define memory pointers CATIPspGroupable *piMemberGroupable = NULL; CATIUnknownList *piListMemberGroups = NULL; IUnknown *piUnk = NULL; CATTry { if (ipiLogicalLineMember && SUCCEEDED(((IUnknown*)ipiLogicalLineMember)->QueryInterface (IID_CATIPspGroupable, (void **)&piMemberGroupable)) && piMemberGroupable) { // Get logical lines if (SUCCEEDED(piMemberGroupable->ListGroups(NULL, &piListMemberGroups)) && piListMemberGroups) { // Get groups unsigned int piListMemberLinesSize = 0; piListMemberGroups->Count(&piListMemberLinesSize); // Find group that is logical line. for (unsigned int iiGroup = 0; iiGroup < piListMemberLinesSize && !opiLogicalLine; iiGroup++) { CATEsuDeleteBaseUnknown(piUnk); if (SUCCEEDED(piListMemberGroups->Item(iiGroup, &piUnk)) && piUnk) { piUnk->QueryInterface(IID_CATIPspLogicalLine, (void **)&opiLogicalLine); } // End if valid logical line. } // End loop on groups. } // End if have logical lines } // End if valid member groupable } // End CATTry CATCatch (CATError, pError) { returnCode = CATReturnError(pError); } CATEndTry; // Release memory CATEsuDeleteBaseUnknown(piMemberGroupable); CATEsuDeleteBaseUnknown(piUnk); CATEsuDeleteBaseUnknown(piListMemberGroups); if (opiLogicalLine) returnCode = CATReturnSuccess; return returnCode; } //----------------------------------------------------------------------------- HRESULT CAADVTubeAttributes::GetObjectAttribute(const IUnknown *ipiObject, CATUnicodeString iuAttributeName, CATICkeParm *&opiAttributeParm) { HRESULT returnCode = CATReturnFailure; opiAttributeParm = NULL; // Define memory pointers CATIPspAttribute *piObjectPspAttr = NULL; CATTry { if (ipiObject && SUCCEEDED(((IUnknown*)ipiObject)->QueryInterface (IID_CATIPspAttribute, (void **)&piObjectPspAttr)) && piObjectPspAttr) { returnCode = piObjectPspAttr->GetLiteral(iuAttributeName, &opiAttributeParm); } } // End CATTry CATCatch (CATError, pError) { returnCode = CATReturnError(pError); } CATEndTry; // Release memory CATEsuDeleteBaseUnknown(piObjectPspAttr); if (opiAttributeParm) returnCode = CATReturnSuccess; return returnCode; } //----------------------------------------------------------------------------- HRESULT CAADVTubeAttributes::GetTestData(const CATICkeParm *ipiPressureParm, const CATICkeParm *ipiNominalSizeParm, const CATICkeParm *ipiMaterialParm, double &oPressure, CATUnicodeString &ouPressure, CATUnicodeString &ouNominalSize, CATUnicodeString &ouMaterial) { HRESULT returnCode = CATReturnFailure; oPressure = 0.0; ouPressure = ""; ouNominalSize = ""; ouMaterial = ""; // Define memory pointers CATICkeInst_var spPressureValue; CATTry { if (ipiPressureParm && ipiNominalSizeParm && ipiMaterialParm) { spPressureValue = ipiPressureParm->Value(); if (!!spPressureValue) oPressure = spPressureValue->AsReal(); // AsReal returns SI unit Pa (N/m2). ouPressure = ipiPressureParm->Show(); ouNominalSize = ipiNominalSizeParm->Show(); ouMaterial = ipiMaterialParm->Show(); returnCode = CATReturnSuccess; } } // End CATTry CATCatch (CATError, pError) { returnCode = CATReturnError(pError); } CATEndTry; // Release memory return returnCode; } .... .... |
[Top]
Finally CAADVTubeAttributes has two methods for testing tube data. TestTubeSize is a simple check to see if the tube has the proper nominal size for the operating pressure on the tubing line. TestTubeMaterial is a likewise simple check that tests tube material against tube nominal size.
.... .... //----------------------------------------------------------------------------- HRESULT CAADVTubeAttributes::TestTubeSize(const double &iPressure, const CATUnicodeString &iuNominalSize, CATUnicodeString &ouAuthorizedSizes) { HRESULT returnCode = S_FALSE; ouAuthorizedSizes = ""; // Define memory pointers CATListValCATUnicodeString listAuthorizedSizes; CATTry { // Set valid nominal sizes. if (0.0 <= iPressure && 100000.0 >= iPressure) { listAuthorizedSizes.Append("1/4in"); listAuthorizedSizes.Append("5/16in"); listAuthorizedSizes.Append("3/8in"); listAuthorizedSizes.Append("1/2in"); } else if (200000.0 >= iPressure) { listAuthorizedSizes.Append("1/2in"); listAuthorizedSizes.Append("5/8in"); listAuthorizedSizes.Append("3/4in"); listAuthorizedSizes.Append("1in"); listAuthorizedSizes.Append("1 1/4in"); } else if (300000.0 >= iPressure) { listAuthorizedSizes.Append("1 1/4in"); listAuthorizedSizes.Append("1 1/2in"); listAuthorizedSizes.Append("2in"); } // Test for violation. if (!listAuthorizedSizes.Locate(iuNominalSize)) { // Nominal size is not authorized. returnCode = CATReturnSuccess; for (int iiSize = 1; iiSize <= listAuthorizedSizes.Size(); iiSize++) { if (1== iiSize) { ouAuthorizedSizes = listAuthorizedSizes[iiSize]; } else { ouAuthorizedSizes += ", " + listAuthorizedSizes[iiSize]; } } } } // End CATTry CATCatch (CATError, pError) { returnCode = CATReturnError(pError); } CATEndTry; // Release memory return returnCode; } //----------------------------------------------------------------------------- HRESULT CAADVTubeAttributes::TestTubeMaterial(const double &iPressure, const CATUnicodeString &iuNominalSize, const CATUnicodeString &iuMaterial, CATUnicodeString &ouAuthorizedMaterialForSize) { HRESULT returnCode = S_FALSE; ouAuthorizedMaterialForSize = ""; // Define memory pointers int nomSizeIndex = 0; int iiSize = 0; CATUnicodeString uCurrentSize; CATListValCATUnicodeString listAuthorizedMaterials; CATTry { // Set valid materials for this size. if (iuNominalSize.Compare("1/4in") || iuNominalSize.Compare("5/16in") || iuNominalSize.Compare("3/8in") || iuNominalSize.Compare("1/2in") || iuNominalSize.Compare("5/8in")) { listAuthorizedMaterials.Append("Carbon steel"); listAuthorizedMaterials.Append("Stainless steel"); } else if (iuNominalSize.Compare("5/8in") || iuNominalSize.Compare("3/4in") || iuNominalSize.Compare("1in") || iuNominalSize.Compare("1 1/4in")) { listAuthorizedMaterials.Append("Carbon steel"); listAuthorizedMaterials.Append("Stainless steel"); listAuthorizedMaterials.Append("Copper"); } else if (iuNominalSize.Compare("1 1/2in") || iuNominalSize.Compare("2in")) { listAuthorizedMaterials.Append("Copper"); listAuthorizedMaterials.Append("Aluminum"); } // Test for violation. if (!listAuthorizedMaterials.Locate(iuMaterial)) { // Material is not authorized returnCode = CATReturnSuccess; for (int iiSize = 1; iiSize <= listAuthorizedMaterials.Size(); iiSize++) { if (1== iiSize) { ouAuthorizedMaterialForSize = listAuthorizedMaterials[iiSize]; } else { ouAuthorizedMaterialForSize += ", " + listAuthorizedMaterials[iiSize]; } } } } // End CATTry CATCatch (CATError, pError) { returnCode = CATReturnError(pError); } CATEndTry; // Release memory return returnCode; } .... .... |
[Top]
The CAAViolationTubeAttributes class stores and reports violation data for a tube attribute violation. It is based on CATPspCheckViolation which should be the base for all violation classes. The constructor takes inputs of the type of check, the name of the check and the NLS resource for the check. These are data used by the Design Validation command and need to be set on all violations.
CAAViolationTubeAttributes also stores data for pressure, nominal size, material and authorized values. These data are specific to the violation and can be any data that is relevant. The SetInfo method sets the data for the violation. The CAADVTubeAttributes design check calls this routine. Since no other code uses this method, its design and interface are specific to the current design check.
The next method, GetCheckViolationData, is used by the Design Validation command and should be overridden. GetCheckViolationData returns the number of rows of data. For CAAViolationTubeAttributes this is always one. (A related method, GetRowCount, is implemented in the base class, CATPspCheckViolation, to return one(1). If you design a violation with more than one row you should also override GetRowCount.) GetCheckViolationData also returns an array of lists of strings. Each element in the array corresponds to one row of data. Since CAAViolationTubeAttributes only has one row of data, only the first element ([0]) of the array is set. Each item in the list corresponds to a column of data. CAAViolationTubeAttributes sets four columns of data, which correspond to the four column titles returned by CAADVTubeAttributes::GetColumnTitles The Design Validation command shows each data element in its appropriate column when reporting violations.
/** * @quickreview eml 07:04:25 Replace tabs with spaces. * @fullreview eml svo 07:04:24 Creation */ //============================================================================= // COPYRIGHT Dassault Systemes 2006 //============================================================================= // // CAAViolationTubeAttributes.cpp // //============================================================================= // // Implementation notes: Violation object // //============================================================================= // // Creation: 2007 April 23 Eric Miller // //============================================================================= #include "CAAViolationTubeAttributes.h" #include "CATError.h" #include "CATErrorMacros.h" #include "CATUnicodeString.h" //----------------------------------------------------------------------------- // CAAViolationTubeAttributes : constructor //----------------------------------------------------------------------------- CAAViolationTubeAttributes::CAAViolationTubeAttributes(const CATUnicodeString& iType, const CATUnicodeString& iCheck, const CATUnicodeString& iResource) :CATPspCheckViolation( iType, iCheck, iResource ) { _uPressure = ""; _uNominalSize = ""; _uMaterial = ""; _uAuthorizedValues = ""; } //----------------------------------------------------------------------------- // CAAViolationTubeAttributes : destructor //----------------------------------------------------------------------------- CAAViolationTubeAttributes::~CAAViolationTubeAttributes() {} //----------------------------------------------------------------------------- void CAAViolationTubeAttributes::SetInfo(CATUnicodeString &iuPressure, CATUnicodeString &iuNominalSize, CATUnicodeString &iuMaterial, CATUnicodeString &iuAuthorizedValues) { _uPressure = iuPressure; _uNominalSize = iuNominalSize; _uMaterial = iuMaterial; _uAuthorizedValues = iuAuthorizedValues; } //----------------------------------------------------------------------------- HRESULT CAAViolationTubeAttributes::GetCheckViolationData(int& oRow, CATListValCATUnicodeString** oLValues) { HRESULT returnCode = CATReturnFailure; oRow = 1; *oLValues = new CATListValCATUnicodeString[oRow]; if ( *oLValues ) { (*oLValues)[0].Append(_uPressure); (*oLValues)[0].Append(_uNominalSize); (*oLValues)[0].Append(_uMaterial); (*oLValues)[0].Append(_uAuthorizedValues); returnCode = CATReturnSuccess; } return returnCode; } |
[Top]
There are two support files for the CAADVTubeAttributes design check code. The first is a dictionary file that tells CATIA that CAADVTubeAttributes is an implementation of a predefined CAA interface. This file is CAAPlantShipInterfaces.edu.dico whose contents are shown below. The line defining CAADVTubeAttributes is highlighted in red. The line shows the object name (CAATubAttr) declared in the CAADVTubeAttributes file. It also shows that it implements the CATIPspDesignValidation interface in the CAAPspDesignValidation library.
# COPYRIGHT DASSAULT SYSTEMES 2004
#======================================================================
#CAAPlantShipInterfaces.edu
#======================================================================
PipingLayout CATIPspKweUserAttr libCAAPspDefineUserProperties
#
# Design validation implementations
CAATubAttr CATIPspDesignValidation libCAAPspDesignValidation
|
The second support file provides natural language capability. Since the code is reporting to users, the output should be in the language they are using. CATIA uses NLS files to allow changing the language of output without changing code. The NLS file for CAADVTubeAttributes is CAAPspDesignValidation.CATNls, whose contents are shown below. The left-hand column contains keys that the code uses to select a line in the file. The right-hand column contains the natural language strings that correspond to the keys. To change the file to another language change the contents of the right-hand column.
TubeAttributeColPressure = "Pressure"; TubeAttributeColSize = "Size"; TubeAttributeColMaterial = "Material"; TubeAttributeColAuthorized = "Authorized Values"; TubeSize = "Tube unauthorized size"; TubeMaterial = "Tube unauthorized material for size"; |
[Top]
This use case has demonstrated how to use the Psp interfaces to add a design check to the design validation command. Specifically, it has illustrated:
[Top]
[1] | Building and Launching a CAA V5 Use Case |
Version: 1 [April 2007] | Document created |
[Top] |
Copyright © 2004, Dassault Systèmes. All rights reserved.