提供一个catia如何画sweep的程序吧
#include <iostream.h>
#include <iomanip.h>
#include "fstream.h"
// Mathematics
#include "CATMathPoint.h" // Mathematical point
// Advanced Mathematics
#include "CATMathSetOfPointsND.h" // Creation of a set of points
#include "CATSoftwareConfiguration.h"
// GeometricObjects
#include "CATGeoFactory.h" // Geometry factory
#include "CATCGMContainerMngt.h" // Management of the geometry factory
#include "CATSplineCurve.h" // Spline creation
#include "CATCrvLimits.h" // Curve limits
#include "CATLine.h"
#include "CATTabulatedCylinder.h"
#include "CATCurve.h"
#include "CATSurface.h"
#include "CATSurLimits.h"
// TopologicalOperators
#include "CATTopWire.h"
#include "CATTopSkin.h"
// NewTopologicalObjects
#include "CATBody.h" // Body
#include "ListPOfCATBody.h" // List of bodies
// Sweep segment
#include "CAATopSweepSegmentSkinSkin.h"
// ---------------------------------------------------------------------------
int main(int iArgc, // Number of arguments (0) or (1)
char** iArgv) // Path to the *.NCGM document generated by this program
{
int rc = 0;
if( 2 < iArgc)
return (1);
char *pFileName = 0;
int toStore = 0;
if (2 == iArgc)
{
toStore = 1;
pFileName = iArgv[1];
}
//----------------------------------------------------------------------------
// 1 - Create the geometry factory and other preliminary operations
//----------------------------------------------------------------------------
//
// a - Factory
//
CATGeoFactory* piGeomFactory = ::CATCreateCGMContainer() ;
if ( 0 == piGeomFactory )
return (1);
cout << "starting " << endl;
// b - Configuration
//
CATSoftwareConfiguration * pConfig = new CATSoftwareConfiguration();
CATTopData topdata(pConfig, NULL);
// -----------------------------------------------------------------------------
// 2 - Create the spine curve (line)
// -----------------------------------------------------------------------------
CATMathPoint startPt, endPt;
startPt.SetCoord(0., 0., 5.);
endPt.SetCoord(0., 0., 25.) ;
CATLine * piSpineCurve = piGeomFactory->CreateLine(startPt,endPt);
if ( 0 == piSpineCurve )
{
::CATCloseCGMContainer(piGeomFactory);
return (1);
}
// -----------------------------------------------------------------------------
// 3 - Create the profiles for tabulated sylinder (splines)
// -----------------------------------------------------------------------------
CATMathSetOfPointsND pointSet1(3,6); // set of points for profile 1
CATMathSetOfPointsND pointSet2(3,5); // set of points for profile 2
double Point1[3]={ 0., 10., 0.} ;
double Point2[3]={ 10., 2., 0.} ;
double Point3[3]={ 15., 17., 0.} ;
double Point4[3]={ 20., 20., 0.} ;
double Point5[3]={ 25., 17., 0.} ;
double Point6[3]={ 30., 0., 0.} ;
double Point7[3]={ 75., 2., 0.} ;
double Point8[3]={ 70., 0., 0.} ;
double Point9[3]={ 60., 5., 0.} ;
double Point10[3]={ 63., 10., 0.} ;
double Point11[3]={ 73., 8., 0.} ;
pointSet1.AddPoint(Point6); //the order of points affects the surface normal
pointSet1.AddPoint(Point5);
pointSet1.AddPoint(Point4);
pointSet1.AddPoint(Point3);
pointSet1.AddPoint(Point2);
pointSet1.AddPoint(Point1);
pointSet2.AddPoint(Point11);
pointSet2.AddPoint(Point10);
pointSet2.AddPoint(Point9);
pointSet2.AddPoint(Point8);
pointSet2.AddPoint(Point7);
//first curve
CATSplineCurve * piProfile1 = piGeomFactory->CreateSplineCurve([$pointSet1,0,1,2,0)]
if ( 0 == piProfile1)
{
::CATCloseCGMContainer(piGeomFactory);
return (1);
}
//second curve
CATSplineCurve * piProfile2 = piGeomFactory->CreateSplineCurve([$pointSet2,0,1,2,0)]
if ( 0 == piProfile2)
{
::CATCloseCGMContainer(piGeomFactory);
return (1);
}
// -----------------------------------------------------------------------------
// 4 - Create the tabulated cylinders
// -----------------------------------------------------------------------------
CATMathDirection cylAxis;
cylAxis.SetCoord(0.,0.,1.);
//first surface
CATTabulatedCylinder * piTabCylinder1 = piGeomFactory->CreateTabulatedCylinder( piProfile1, cylAxis, 0., 20.);
if ( 0 == piTabCylinder1 )
{
::CATCloseCGMContainer(piGeomFactory);
return (1);
}
//second surface
CATTabulatedCylinder * piTabCylinder2 = piGeomFactory->CreateTabulatedCylinder( piProfile2, cylAxis, -10., 30.);
if ( 0 == piTabCylinder2 )
{
::CATCloseCGMContainer(piGeomFactory);
return (1);
}
// -----------------------------------------------------------------------------
// 5 - Create the spine wire
// -----------------------------------------------------------------------------
CATLONG32 nbCurve = 1;
CATCurve ** listOfCurves = new CATCurve * [nbCurve];
listOfCurves[0] = (CATCurve*)piSpineCurve;
CATCrvLimits curLim[1];
CATOrientation orient[1]={1};
listOfCurves[0]->GetLimits( curLim[0] );
CATTopWire * pWireOp = CATCreateTopWire(piGeomFactory,
&topdata,
1,
listOfCurves,
curLim,
orient);
delete [] listOfCurves ;
listOfCurves = 0;
if ( 0 == pWireOp )
{
::CATCloseCGMContainer(piGeomFactory);
return (1);
}
pWireOp->Run();
CATBody * piSpineWire = pWireOp->GetResult();
delete pWireOp ;
pWireOp = 0;
if ( 0 == piSpineWire )
{
cout << "Could not create spine wire " << endl;
::CATCloseCGMContainer(piGeomFactory);
return (1);
}
// -----------------------------------------------------------------------------
// 6 - Create the guide skins
// -----------------------------------------------------------------------------
//first skin
CATSurLimits surLim1;
piTabCylinder1->GetLimits(surLim1);
CATTopSkin * pSkinOp1 = CATCreateTopSkin( piGeomFactory ,
&topdata,
piTabCylinder1,
[$surLim1)]
if ( 0 == pSkinOp1 )
{
::CATCloseCGMContainer(piGeomFactory);
return (1);
}
pSkinOp1->Run();
CATBody * piSkin1 = pSkinOp1->GetResult();
delete pSkinOp1 ;
pSkinOp1 = 0;
if ( 0 == piSkin1 )
{
cout << "Could not create first skin " << endl;
::CATCloseCGMContainer(piGeomFactory);
return (1);
}
//second skin
CATSurLimits surLim2;
piTabCylinder2->GetLimits(surLim2);
CATTopSkin * pSkinOp2 = CATCreateTopSkin( piGeomFactory ,
&topdata,
piTabCylinder2,
[$surLim2)]
if ( 0 == pSkinOp2 )
{
::CATCloseCGMContainer(piGeomFactory);
return (1);
}
pSkinOp2->Run();
CATBody * piSkin2 = pSkinOp2->GetResult();
delete pSkinOp2 ;
pSkinOp2 = 0;
if ( 0 == piSkin2 )
{
cout << "Could not create second skin " << endl;
::CATCloseCGMContainer(piGeomFactory);
return (1);
}
// -----------------------------------------------------------------------------
// 7- Create the sweep segment skin skin
// -----------------------------------------------------------------------------
rc = CAATopSweepSegmentSkinSkin(piGeomFactory,[$topdata,piSkin1,piSkin2,piSpineWire)]
// -----------------------------------------------------------------------------
// 8 - Cleaning operations
// -----------------------------------------------------------------------------
piGeomFactory->Remove(piSpineCurve);
piGeomFactory->Remove(piProfile1);
piGeomFactory->Remove(piProfile2);
piGeomFactory->Remove(piTabCylinder1);
piGeomFactory->Remove(piTabCylinder1);
pConfig->Release();
//----------------------------------------------------------------------------
// 9 - Save the model
//----------------------------------------------------------------------------
if( 1 == toStore)
{
cout << "Writing the model" << endl;
#ifdef _WINDOWS_SOURCE
ofstream filetowrite(pFileName, ios::binary ) ;
#else
ofstream filetowrite(pFileName,ios::out,filebuf::openprot) ;
#endif
::CATSaveCGMContainer(piGeomFactory,filetowrite);
filetowrite.close();
}
::CATCloseCGMContainer(piGeomFactory);
return (rc);
} |