#include "CATSessionServices.h"
#include "CATSession.h"
#include "CATDocument.h"
#include "CATDocumentServices.h"
#include "CATInit.h"
#include "CATIPrtContainer.h"
#include "CATIPrtPart.h"
#include "CATISpecObject.h"
#include "CATIInertia.h"
#include "CATISpaEnvironment.h"
#include <iostream.h>
void main(int argc, char * argv[])
{
//CREAT SESSION
char* sessionName = "artmeasure_Session";
CATSession* pSession = NULL;
HRESULT rc = reate_Session(sessionName,
pSession);
if (FAILED(rc))
{
cout <<"create session erro!" <<endl <<flush;
return;
}
//open doc
CATDocument* pDoc = NULL;
rc = CATDocumentServicespenDocument(argv[1],
pDoc);
if (FAILED(rc)||NULL==pDoc)
{
cout << "open document erro!" <<endl <<flush;
return;
}
//Queries on the document to get the root container
CATInit* pDocInit = NULL;
rc = pDoc -> QueryInterface(IID_CATInit,
(void**) [$pDocInit)]
if (FAILED(rc))
{
cout <<"Query CATInit erro!" <<endl <<flush;
return;
}
CATIPrtContainer *pSpecContainer = NULL ;
pSpecContainer = (CATIPrtContainer*)pDocInit->GetRootContainer("CATIPrtContainer");
if (FAILED(rc)||NULL==pSpecContainer)
{
cout <<"Query CATIPartContainer erro!" <<endl <<flush;
return;
}
pDocInit->Release();
pDocInit = NULL;
//Initiate Enviroment
CATISpaEnvironment *piSpaEnvironment = NULL;
rc = pDoc->QueryInterface(IID_CATISpaEnvironment,
(void**)[$piSpaEnvironment)]
if(SUCCEEDED(rc))
cout <<"QI IID_CATISpaEnvironment OK!!!" <<endl <<flush;
else
return;
piSpaEnvironment->Init();
cout <<"Initiate Enviroment ok!!" <<endl <<flush;
//Retrieve CATIPrtPart
CATIPrtPart_var spPart = pSpecContainer -> GetPart();
if (NULL_var == spPart)
{
cout <<"Retrieve CATIPrtPart_var erro!" <<endl <<flush;
return;
}
pSpecContainer->Release();
pSpecContainer=NULL;
//Query CATIInertia
CATIInertia* piInertia = NULL;
rc = spPart -> QueryInterface (IID_CATIInertia,
(void**) [$piInertia)]
if (SUCCEEDED(rc) && NULL != piInertia)
{
cout <<"Query CATIInertia OK!!" <<endl <<flush;
}
else
return;
//Retrieve CATIInertia's feature
double thedensity;
double themass;
rc = piInertia -> GetMass([$thedensity,&themass)]
if (SUCCEEDED(rc))
{
cout <<"The Density of The Part is : "<<thedensity <<endl<<flush;
cout <<"The Mass of the Part is : "<<themass <<endl<<flush;
}
else
return;
double theCOGposition[3];
rc = piInertia -> GetCOGPosition(theCOGposition);
if (SUCCEEDED(rc))
{
cout <<"The COGposition is :" << theCOGposition[0] <<" "<<theCOGposition[1] <<" " <<theCOGposition[2] <<endl <<flush;
}
else
return;
double theInertia[9];
rc = piInertia -> GetInertiaMatrix([$thedensity,theInertia)]
if (SUCCEEDED(rc))
{
cout <<"The Inertia of the Product is :" ;
for(int inerNum = 0; inerNum < 9; inerNum++)
{
if(inerNum%3==0)
cout <<endl <<flush;
cout << theInertia[inerNum] <<" ";
}
}
else
return;
piInertia->Release();
piInertia = NULL;
piSpaEnvironment -> Release();
piSpaEnvironment = NULL;
//Remove Doc And Delete Session
rc = CATDocumentServices::Remove (*pDoc);
if (FAILED(rc))
{
cout <<"Doc Delete erro!"<<endl<<flush;
return;
}
rc = :elete_Session("artmeasure_Session");
if (FAILED(rc))
{
cout <<"Session Delete erro!"<<endl<<flush;
return;
}
}
//以上是完整代码,和大家分享,欢迎交流,欢迎指导。。。。 |