解决了
解决了,公开CATIBuildShape部分程序供大家分享
// COPYRIGHT WSH 2004
//===================================================================
//
// WSHEDSPRTHPCHolePartBuildShape.cpp
// Provide implementation to interface
// CATIBuildShape
//
//===================================================================
//
// Usage notes: BuiltShape Inplement class
//
//===================================================================
// May 2004 Creation: Code generated by the CAA wizard zzsou1
//===================================================================
#include "WSHEDSPRTHPCHolePartBuildShape.h"
#include "CATIUpdateError.h"
#include "CATIGeometricalElement.h"
#include "CATISpecObject.h"
#include "CATMathDirection.h"
#include "CATIPrtFactory.h"
#include "CATISketchFactory.h"
#include "CATInit.h"
#include "CATListOfDouble.h"
#include "CATIMfProcReport.h"
#include "CATGeoFactory.h"
#include "CATSoftwareConfiguration.h"
#include "CATTopData.h"
#include "CATSolidCylinder.h"
#include "CATBody.h"
#include "CATDynBoolean.h"
#include "CATCGMJournalList.h"
#include "CATCGMJournalInfo.h"
#include "CATCGMJournalItem.h"
#include "CATIBRepAccess.h"
#include "CATMfBRepDecode.h"
#include "CATCell.h"
#include "CATFace.h"
#include "CATIContainerOfDocument.h"
#include "CATDocument.h"
#include "WSHIDSPRTHPCHolePart.h"
#include "WSHDSPRTHPCBuildErr.h"
#include "WSHDSPRTHPCListOfWSHIDSPRTHPCStage.h"
#include "WSHDSPRTHPCStage.h"
//debug
#include "CATIVisProperties.h"
#include "CATVisGeomType.h"
#include "CATVisPropertiesValues.h"
#include "CATIMechanicalTool.h"
#include "WSHCMNBdg.h"
CATImplementClass( WSHEDSPRTHPCHolePartBuildShape,
DataExtension,
CATBaseUnknown,
WSHDSPRTHPCHole );
//-----------------------------------------------------------------------------
// WSHEDSPRTHPCHolePartBuildShape : constructor
//-----------------------------------------------------------------------------
#define PCODE 1014005
#define PNAME "WSHEDSPRTHPCHolePartBuildShape::WSHEDSPRTHPCHolePartBuildShape"
WSHEDSPRTHPCHolePartBuildShape::WSHEDSPRTHPCHolePartBuildShape():
WSHCADCMNMDLExtIBuild()
{
WSHCMNBdgintrtn( PCODE, PNAME);
}
//-----------------------------------------------------------------------------
// WSHEDSPRTHPCHolePartBuildShape : destructor
//-----------------------------------------------------------------------------
#undef PNAME
#define PNAME "WSHEDSPRTHPCHolePartBuildShape::~WSHEDSPRTHPCHolePartBuildShape"
WSHEDSPRTHPCHolePartBuildShape::~WSHEDSPRTHPCHolePartBuildShape()
{
WSHCMNBdgintrtn( PCODE, PNAME);
}
// Tie the implementation to its interface
// ---------------------------------------
#include "TIE_CATIBuildShape.h"
TIE_CATIBuildShape( WSHEDSPRTHPCHolePartBuildShape);
//-----------------------------------------------------------------------------
// Implements CATIBuildShape::BuildShape
//-----------------------------------------------------------------------------
#undef PNAME
#define PNAME "WSHEDSPRTHPCHolePartBuildShape::BuildShape"
int WSHEDSPRTHPCHolePartBuildShape::BuildShape ()
{
WSHCMNBdgintrtn( PCODE, PNAME);
int Ret = 0;
HRESULT rc = S_OK;
do{
// reset update error
CATIUpdateError_var spUpdateError = this;
if(!spUpdateError){
rc = CATReturnError(new WSHDSPRTHPCBuildErr("WSHEDSPRTHPCHolePartBuildShapeErr_1001705001"));
break;
}
spUpdateError->UnsetUpdateError();
CATIGeometricalElement_var spGeomElement = this;
if(!!spGeomElement){
spGeomElement->DeleteScope();
}
// get feature attr
WSHIDSPRTHPCHolePart_var spHolePart = this;
if(!spHolePart){
rc = CATReturnError(new WSHDSPRTHPCBuildErr("WSHEDSPRTHPCHolePartBuildShapeErr_1001705002"));
break;
}
CATMathPoint OriginPoint = spHolePart->GetOrigin();
CATMathDirection HolePartDirection = spHolePart->GetAxisDirection();
double OffsetValue = spHolePart->GetOffsetValue();
int StepValue = spHolePart->GetStepValue();
CATRawColldouble* pDiamterValueList = spHolePart->GetDiameterValue();
CATRawColldouble* pDepthValue = spHolePart->GetDepthValue();
// get factory
CATGeoFactory_var spGeoFactory = GetGeoFactory();
if(!spGeoFactory){
rc = CATReturnError(new WSHDSPRTHPCBuildErr("WSHEDSPRTHPCHolePartBuildShapeErr_1001705003"));
break;
}
CATGeoFactory* pImpGeoFactory = spGeoFactory->GetImplicitGeoFactory();
if( !pImpGeoFactory ) {
rc = CATReturnError(new WSHDSPRTHPCBuildErr("WSHEDSPRTHPCHolePartBuildShapeErr_1001705003"));
break;
}
CATSoftwareConfiguration* pSoftwareConfiguration = new CATSoftwareConfiguration();
// create dumy journal
CATCGMJournalList* pJournalList = new CATCGMJournalList(
pSoftwareConfiguration,
NULL
);
if( !pJournalList ) {
rc = CATReturnError(new WSHDSPRTHPCBuildErr("WSHEDSPRTHPCHolePartBuildShapeErr_1001705004"));
break;
}
CATTopData topData( pSoftwareConfiguration, pJournalList );
// Get ProcReport
CATIMfProcReport_var spProcReport = this;
if(!spProcReport){
rc = CATReturnError(new WSHDSPRTHPCBuildErr("WSHEDSPRTHPCHolePartBuildShapeErr_1001705005"));
break;
}
CATLISTV(CATBaseUnknown_var) ListSpec;
CATListOfCATUnicodeString ListKeys;
spProcReport->CreateProcReport(ListSpec,ListKeys,0);
// real journal list
CATCGMJournalList* pMainJournalList = spProcReport->GetCGMJournalList();
if(!pMainJournalList){
rc = CATReturnError(new WSHDSPRTHPCBuildErr("WSHEDSPRTHPCHolePartBuildShapeErr_1001705005"));
break;
}
CATSoftwareConfiguration* pSoftwareConfigurationMain = new CATSoftwareConfiguration();
CATTopData topDataMain( pSoftwareConfigurationMain, pMainJournalList );
CATLISTP(CATGeometry) operands;
// create a temp stage info
CATLISTV(WSHIDSPRTHPCStage_var) StageListTemp;
// face <-> Info index table
int InfoIndex[1][4] = { 1, 1, 2, 0 }; // 0:頂面 1:側面 2:底面 999:無定義
// Create cylinder soild
CATBody_var spTotalBody = pImpGeoFactory->CreateBody();
if ( !spTotalBody ) {
rc = CATReturnError(new WSHDSPRTHPCBuildErr("WSHEDSPRTHPCHolePartBuildShapeErr_1001705006"));
break;
}
CATBody* pBoolResultBody = NULL;
double OffsetStart = OffsetValue;
for ( int iCnt = 1; iCnt <= StepValue ; iCnt++ ) {
// create stage list
WSHDSPRTHPCStage* pStage = new WSHDSPRTHPCStage();
if( !pStage ) {
rc = CATReturnError(new WSHDSPRTHPCBuildErr("WSHEDSPRTHPCHolePartBuildShapeErr_1001705009"));
break;
}
WSHIDSPRTHPCStage_var spStage = pStage;
pStage->Release();
pStage = NULL;
if( !spStage ) {
rc = CATReturnError(new WSHDSPRTHPCBuildErr("WSHEDSPRTHPCHolePartBuildShapeErr_1001705009"));
break;
}
// top center point
if ( iCnt >1 ) {
OffsetStart += (*pDepthValue)[iCnt-1];
}
CATMathPoint StartPoint( OriginPoint.GetX() + HolePartDirection.GetX()*OffsetStart,
OriginPoint.GetY() + HolePartDirection.GetY()*OffsetStart,
OriginPoint.GetZ() + HolePartDirection.GetZ()*OffsetStart );
// bottom center point
double OffsetEnd = OffsetStart + (*pDepthValue)[iCnt];
CATMathPoint EndPoint( OriginPoint.GetX() + HolePartDirection.GetX()*OffsetEnd,
OriginPoint.GetY() + HolePartDirection.GetY()*OffsetEnd,
OriginPoint.GetZ() + HolePartDirection.GetZ()*OffsetEnd );
// create cylinder
CATSolidCylinder* pCylinder = NULL;
CATTry{
pCylinder = CATCreateSolidCylinder(pImpGeoFactory,
&topData,
StartPoint,
EndPoint,
(*pDiamterValueList)[iCnt]/2);
if(!pCylinder){
rc = CATReturnError(new WSHDSPRTHPCBuildErr("WSHEDSPRTHPCHolePartBuildShapeErr_1001705007"));
break;
}
}CATCatch(CATError, pError){
rc = CATReturnError(new WSHDSPRTHPCBuildErr("WSHEDSPRTHPCHolePartBuildShapeErr_1001705007"));
delete pCylinder;
pCylinder = NULL;
break;
}CATEndTry;
CATBody* pCylinderBody = pCylinder->GetResult();
if(!pCylinderBody){
rc = CATReturnError(new WSHDSPRTHPCBuildErr("WSHEDSPRTHPCHolePartBuildShapeErr_1001705007"));
break;
}
CATBody_var spCylinderBody = pCylinderBody;
if(!spCylinderBody){
rc = CATReturnError(new WSHDSPRTHPCBuildErr("WSHEDSPRTHPCHolePartBuildShapeErr_1001705007"));
break;
}
CATLISTP(CATCell) cellListFace;
spCylinderBody->GetAllCells(cellListFace,2);
// face index
CATLISTV(CATBaseUnknown_var) WallList;
CATLISTV(CATBaseUnknown_var) BottomList;
for ( int iInfoCnt = 1; iInfoCnt<=cellListFace.Size(); iInfoCnt++ ) {
CATFace* pFace = (CATFace*)cellListFace[iInfoCnt];
if(!pFace){
continue;
}
CATFace_var spFace = pFace;
if ( !spFace ) {
continue;
}
pMainJournalList->ReportCreation( operands, (CATGeometry*)pFace , new CATCGMJournalInfo( iCnt*10 + InfoIndex[0][iInfoCnt-1] ) );
}
spStage->SetWallBRepList( WallList );
spStage->SetBottomBRepList( BottomList );
StageListTemp.Append( spStage );
// get the sum body of cylindersる
CATDynBoolean* pOperatorBool = CATCreateDynBoolean(pImpGeoFactory,
&topDataMain,
CATBoolUnion,
spTotalBody,
spCylinderBody);
if(!pOperatorBool){
rc = CATReturnError(new WSHDSPRTHPCBuildErr("WSHEDSPRTHPCHolePartBuildShapeErr_1001705008"));
break;
}
CATTry{
pOperatorBool->Run();
}
CATCatch(CATError,pError){
rc = CATReturnError(new WSHDSPRTHPCBuildErr("WSHEDSPRTHPCHolePartBuildShapeErr_1001705008"));
break;
}
CATEndTry;
if ( !!pBoolResultBody ) {
pImpGeoFactory->Remove( pBoolResultBody, CATICGMContainer::RemoveDependancies );
pBoolResultBody = NULL;
}
pBoolResultBody = pOperatorBool->GetResult();
if(!pBoolResultBody){
rc = CATReturnError(new WSHDSPRTHPCBuildErr("WSHEDSPRTHPCHolePartBuildShapeErr_1001705008"));
break;
}
spTotalBody = pBoolResultBody;
if(!spTotalBody){
rc = CATReturnError(new WSHDSPRTHPCBuildErr("WSHEDSPRTHPCHolePartBuildShapeErr_1001705008"));
break;
}
if(!!pOperatorBool){
delete pOperatorBool;
pOperatorBool = NULL;
}
if ( !!pCylinderBody ) {
pImpGeoFactory->Remove( pCylinderBody, CATICGMContainer::RemoveDependancies );
pCylinderBody = NULL;
}
if(!!pCylinder){
delete pCylinder;
pCylinder = NULL;
}
} //for
pMainJournalList->Tass();
// pre-save face info before store a Journal
int InfoArray[60] = { 0, 0 };
CATLISTP(CATCGMJournal) ListOfCATFaceType;
pMainJournalList->SearchReportsAbout(CATFaceType,ListOfCATFaceType);
for ( int iCntList=1; iCntList<= ListOfCATFaceType.Size(); iCntList++) {
if ( !(ListOfCATFaceType[iCnt]) ) {
continue;
}
if ( (ListOfCATFaceType[iCntList])->GetType() == CATCGMJournal::Creation ) {
CATCGMJournalItem* pJItem = (ListOfCATFaceType[iCntList])->CastToReportItem();
if (!pJItem ) {
continue;
}
const CATCGMJournalInfo* pJInfo = pJItem->GetAssociatedInfo();
if ( !pJInfo ) {
continue;
}
CATLONG32 InfoNum = pJInfo->GetNumber();
if ( InfoNum < 10 || InfoNum > 59 ) {
continue;
}
if ( InfoArray[InfoNum] ) {
continue;
}
CATGeometry* pGeometry = pJItem->GetConstructedObject();
if ( !pGeometry ) {
continue;
}
CATGeometry_var spGeometry = pGeometry;
if ( !spGeometry ) {
continue;
}
// Set stage info
int StageNumT = InfoNum/10;
if ( InfoNum == StageNumT*10 ) continue;
if ( InfoNum == StageNumT*10 + 1 ) {
(StageListTemp[StageNumT])->WallBRepListAppend(spGeometry);
}
else {
(StageListTemp[StageNumT])->BottomBRepListAppend(spGeometry);
}
InfoArray[InfoNum] = 1;
}
}
// save ProcReport
if( SUCCEEDED(rc) && spProcReport != NULL){
spTotalBody->SetMode( CatCGMExplicit );
spTotalBody->Completed( TRUE );
spProcReport->StoreProcReport(spTotalBody,NoCopy,0);
}
// CATIContainerインターフェースを取得する
CATILinkableObject_var spILinkableOnActive = this;
if( !spILinkableOnActive ) {
rc = CATReturnError(new WSHDSPRTHPCBuildErr("WSHEDSPRTHPCHolePartBuildShapeErr_1001705010"));
break;
}
CATDocument* pDocument = spILinkableOnActive->GetDocument();
if ( !pDocument ) {
rc = CATReturnError(new WSHDSPRTHPCBuildErr("WSHEDSPRTHPCHolePartBuildShapeErr_1001705010"));
break;
}
CATIContainerOfDocument* piContOfDoc = NULL;
rc = pDocument->QueryInterface( IID_CATIContainerOfDocument, (void**)[$piContOfDoc )]
if( FAILED(rc) || !piContOfDoc ) {
rc = CATReturnError(new WSHDSPRTHPCBuildErr("WSHEDSPRTHPCHolePartBuildShapeErr_1001705010"));
break;
}
CATIContainerOfDocument_var spContOfDoc = piContOfDoc;
piContOfDoc->Release();
piContOfDoc = NULL;
if ( !spContOfDoc ) {
rc = CATReturnError(new WSHDSPRTHPCBuildErr("WSHEDSPRTHPCHolePartBuildShapeErr_1001705010"));
break;
}
CATIContainer* pCont = NULL;
rc = spContOfDoc->GetBRepContainer(pCont);
if ( FAILED(rc) || !pCont ) {
rc = CATReturnError(new WSHDSPRTHPCBuildErr("WSHEDSPRTHPCHolePartBuildShapeErr_1001705010"));
break;
}
CATIContainer_var spCont = pCont;
if ( !spCont ) {
rc = CATReturnError(new WSHDSPRTHPCBuildErr("WSHEDSPRTHPCHolePartBuildShapeErr_1001705010"));
break;
}
// Stage List
CATLISTV(WSHIDSPRTHPCStage_var) StageList;
// decode fave info to Brep
for ( int iStepNum = 1; iStepNum <= StageListTemp.Size(); iStepNum++ ) {
// caeate stage info
WSHDSPRTHPCStage* pStage = new WSHDSPRTHPCStage();
if( !pStage ) {
rc = CATReturnError(new WSHDSPRTHPCBuildErr("WSHEDSPRTHPCHolePartBuildShapeErr_1001705009"));
break;
}
WSHIDSPRTHPCStage_var spStage = pStage;
pStage->Release();
pStage = NULL;
if( !spStage ) {
rc = CATReturnError(new WSHDSPRTHPCBuildErr("WSHEDSPRTHPCHolePartBuildShapeErr_1001705009"));
break;
}
// INdex face( in BRep)
CATLISTV(CATBaseUnknown_var) WallBRepList;
for ( int iWallCnt = 1; iWallCnt <= ((StageListTemp[iStepNum])->GetWallBRepList()).Size(); iWallCnt++ ) {
CATIBRepAccess_var spIBRepAccess = CATBRepDecode( spCont,
((StageListTemp[iStepNum])->GetWallBRepList())[iWallCnt],
spTotalBody );
if ( !spIBRepAccess ) {
rc = CATReturnError(new WSHDSPRTHPCBuildErr("WSHEDSPRTHPCHolePartBuildShapeErr_1001705011"));
break;
}
WallBRepList.Append(spIBRepAccess);
//dubug
int iMACopyFlag = spHolePart->GetMACopyFlag();
if ( spHolePart->GetMACopyFlag() ) {
CATIVisProperties *piGraphProp = NULL;
rc = spIBRepAccess->QueryInterface( IID_CATIVisProperties,
(void**)[$ piGraphProp)]
if ( FAILED(rc) ) {
break;
}
CATVisPropertiesValues Attribut;
Attribut.SetColor(255, 255, 0); // yellow
piGraphProp->SetPropertiesAtt(Attribut, CATVPColor , CATVPMesh );
piGraphProp->Release();
piGraphProp = NULL ;
}
}
spStage->SetWallBRepList( WallBRepList );
CATLISTV(CATBaseUnknown_var) BottomBRepList;
for ( int iBottomCnt = 1; iBottomCnt <= ((StageListTemp[iStepNum])->GetBottomBRepList()).Size(); iBottomCnt++ ) {
CATIBRepAccess_var spIBRepAccess = CATBRepDecode( spCont,
((StageListTemp[iStepNum])->GetBottomBRepList())[iBottomCnt],
spTotalBody );
if ( !spIBRepAccess ) {
rc = CATReturnError(new WSHDSPRTHPCBuildErr("WSHEDSPRTHPCHolePartBuildShapeErr_1001705011"));
break;
}
BottomBRepList.Append(spIBRepAccess);
//dubug
int iMADispFlag = spHolePart->GetMADispFlag();
if ( spHolePart->GetMADispFlag() ) {
CATIVisProperties *piGraphProp = NULL;
rc = spIBRepAccess->QueryInterface( IID_CATIVisProperties,
(void**)[$ piGraphProp)]
if ( FAILED(rc) ) {
break;
}
CATVisPropertiesValues Attribut;
Attribut.SetColor(0, 255, 255); // yellow
piGraphProp->SetPropertiesAtt(Attribut, CATVPColor , CATVPMesh );
piGraphProp->Release();
piGraphProp = NULL ;
}
}
spStage->SetBottomBRepList( BottomBRepList );
StageList.Append(spStage);
} //for
//
// FunFromMaTeam( spHolePart->GetCircle(), StageList, spHolePart->GetMACopyFlag(), spHolePart->GetMADispFlag() );
} while ( FALSE );
SUCCEEDED( rc ) ? Ret = 1 : Ret = 0 ;
return Ret;
} |