Making an object craeted in CATGeoFactory show up in a part

Ammon Hepworth

Making an object craeted in CATGeoFactory show up in a part

CATIA's CATGeoFactory allows you to create objects that are not included in the CATIGSMFactory (A NURBS surface for example).  The trouble is these objects are purely mathematical and not viewable in CATIA.  Does anyone know a simple way to take an object created with the CATGeoFactory and visualize it in CATIA?

Thanks,

Ammon

(CAA RADE question)

Ammon Hepworth

RE: Making an object craeted in CATGeoFactory show up in a part
(in response to Ammon Hepworth)
I figured it out. Here is code to create a NURBS curve and make it show up in a CATIA:

HRESULT rc;
rc = NULL;

CATSession* pSession = NULL;
rc = GetPtrSession(pSession);

CATIIniInteractiveSession* interSession = NULL;
rc = pSession->QueryInterface(IID_CATIIniInteractiveSession,(void**) &interSession);

CATIEditor * pInterSesEditor = NULL ;
rc = interSession->New("Part", &pInterSesEditor);

CATFrmEditor* pEditor = pInterSesEditor->GetEditor();

if(pEditor == NULL)
{
printf("error getting the FRM editor");
}

CATDocument *pDoc = pEditor->GetDocument();

CATIContainerOfDocument_var spConODocs = pDoc;
CATIContainer* pSpecContainer = NULL;
HRESULT hr = spConODocs->GetSpecContainer(pSpecContainer);

if(spConODocs == NULL_var)
{
printf("error getting the container of documents");
}

spGSMFactory = NULL_var;
spPrtFactory = NULL_var;
spParmFactory = NULL_var;
spParamDictionary = NULL_var;

spGSMFactory = pSpecContainer;
spPrtFactory = pSpecContainer;
spParmFactory = pSpecContainer;
spParamDictionary = CATCkeGlobalFunctions::GetParmDictionary();

//-----------------------------------------------------------------------------
// 1- Initializes the factory
//-----------------------------------------------------------------------------

CATIContainer* spCGMContainer;
hr = spConODocs->GetResultContainer(spCGMContainer);
CATGeoFactory_var piGeomFactory = spCGMContainer;

//-----------------------------------------------------------------------------
// 2- Creation of the grid of points to be passed as the
// Knot vector argument
//-----------------------------------------------------------------------------
//
int nbPoleU = 5;
int nbPoleV = 5;
CATMathGridOfPoints gridOfPoints(nbPoleU,nbPoleV);

// Row 0
gridOfPoints.SetPoint(CATMathPoint( 0., 0., 0.),0,0);
gridOfPoints.SetPoint(CATMathPoint(10., 0., 0.),0,1);
gridOfPoints.SetPoint(CATMathPoint(20., 0., 0.),0,2);
gridOfPoints.SetPoint(CATMathPoint(30., 0., 0.),0,3);
gridOfPoints.SetPoint(CATMathPoint(40., 0., 0.),0,4);

// Row 1
gridOfPoints.SetPoint(CATMathPoint( 0.,10., 0.),1,0);
gridOfPoints.SetPoint(CATMathPoint(10.,10.,-10.),1,1);
gridOfPoints.SetPoint(CATMathPoint(20.,10.,-10.),1,2);
gridOfPoints.SetPoint(CATMathPoint(30.,10.,-10.),1,3);
gridOfPoints.SetPoint(CATMathPoint(40.,10., 0.),1,4);

// Row 2
gridOfPoints.SetPoint(CATMathPoint( 0.,20., 0.),2,0);
gridOfPoints.SetPoint(CATMathPoint(10.,20.,-40.),2,1);
gridOfPoints.SetPoint(CATMathPoint(20.,20.,-40.),2,2);
gridOfPoints.SetPoint(CATMathPoint(30.,20., -40.),2,3);
gridOfPoints.SetPoint(CATMathPoint(40.,20., 0.),2,4);

// Row 4
gridOfPoints.SetPoint(CATMathPoint( 0.,30., 0.),3,0);
gridOfPoints.SetPoint(CATMathPoint(10.,30., -10.),3,1);
gridOfPoints.SetPoint(CATMathPoint(20.,30., -10.),3,2);
gridOfPoints.SetPoint(CATMathPoint(30.,30., -10.),3,3);
gridOfPoints.SetPoint(CATMathPoint(40.,30., 0.),3,4);

// Row 5
gridOfPoints.SetPoint(CATMathPoint( 0.,40., 0.),4,0);
gridOfPoints.SetPoint(CATMathPoint(10.,40., 0.),4,1);
gridOfPoints.SetPoint(CATMathPoint(20.,40., 0.),4,2);
gridOfPoints.SetPoint(CATMathPoint(30.,40., 0.),4,3);
gridOfPoints.SetPoint(CATMathPoint(40.,40., 0.),4,4);

// Display the control points
//
for (int i = 0; i < nbPoleU; i++)
{
for (int j = 0; j < nbPoleV; j++)
{
CATMathPoint ptToBeDisplayed = gridOfPoints.GetPoint(i,j);
CATCartesianPoint* piCartPt = piGeomFactory->CreateCartesianPoint(ptToBeDisplayed);
}
}
//-----------------------------------------------------------------------------
// 3 - Creation of the knot vectors
//-----------------------------------------------------------------------------
//

CATLONG32 IsPeriodic= 0;
CATLONG32 Degree= 4;
CATLONG32 KnotsCount= 2;
double Knots[]= {0.,10.};
CATLONG32 Multiplicities[]= {5,5};
CATLONG32 IndexOffset= 1;

CATKnotVector NonUniformU(Degree,IsPeriodic,KnotsCount,Knots,
Multiplicities,IndexOffset);
CATKnotVector NonUniformV(Degree,IsPeriodic,KnotsCount,Knots,
Multiplicities,IndexOffset);

//-----------------------------------------------------------------------------
// 4 - Creation of a rational NURBS surface
//-----------------------------------------------------------------------------

CATLONG32 isRational=1;
double * aWeights=new double[nbPoleU*nbPoleV];
for (i = 0; i < nbPoleU*nbPoleV; i++)
{
aWeights = 1.;
}

// NURBS Surface creation
//
CATNurbsSurface * piSurf1 = piGeomFactory->
CATCreateNurbsSurface(NonUniformU, NonUniformV,isRational,gridOfPoints,aWeights);
if (NULL==piSurf1)
{
printf( "NURBS surface could not be created");
::CATCloseCGMContainer(piGeomFactory);
return (CATStatusChangeRCAborted);
}

// Assign a weight value (80) to the (3,3) poles
//
//piSurf1->SetOneWeight(3,3,80);

delete [] aWeights;
aWeights = NULL;

//-----------------------------------------------------------------------------
// 5 - Creation of the skin
//-----------------------------------------------------------------------------

CATSurLimits surMaxLimits ;
piSurf1->GetMaxLimits(surMaxLimits) ;

CATSoftwareConfiguration * pConfig = new CATSoftwareConfiguration();
CATTopData topdata(pConfig);

CATTopSkin * pSkinOpe =::CATCreateTopSkin(piGeomFactory,
&topdata,
piSurf1,
&surMaxLimits);

if (NULL==pSkinOpe)
{
::CATCloseCGMContainer(piGeomFactory);
return (CATStatusChangeRCAborted);
}

pSkinOpe->Run();

// Gets the resulting body
CATBody * piSkinBody = pSkinOpe->GetResult();

if (NULL==piSkinBody)
{
::CATCloseCGMContainer(piGeomFactory);
return (CATStatusChangeRCAborted);
}

// Deletes the operator
delete pSkinOpe;
pSkinOpe=NULL;

CATIDatumFactory_var spDatumFactory;
spDatumFactory = pSpecContainer;
CATISpecObject* oDatumFeature;
spDatumFactory->InstanciateDatum(piSkinBody, oDatumFeature);

oDatumFeature->Update();
spCurObj = oDatumFeature;
spCurObj->InsertInProceduralView();

pConfig->Release();

I hope this helps someone out there.

Ammon