Open C、Open C++和NXOpen C++混合开发
来源:互联网 发布:终极面试 知乎 编辑:程序博客网 时间:2024/06/16 22:41
三者的关系我在以前的文章中讲过了。但是他们都不是孤立的,互相可以使用。
下面举了个不同部分用不同的代码,
函数形式的是Open C,也就是API了
类形式不带NXOpen的是Open C++,否则是NXOpen C++了。
Tag是所有之间的桥梁。
//NXOpen header files
#include <NXOpen/Session.hxx>
#include <NXOpen/Part.hxx>
#include <NXOpen/PartCollection.hxx>
//#include <NXOpen/Point.hxx>
#include <NXOpen/Line.hxx>
#include <NXOpen/CurveCollection.hxx>
#include <NXOpen/Arc.hxx>
#include <NXOpen/NXObjectManager.hxx>
//#include <NXOpen/NXString.hxx>
//UFunc Headers
#include <uf_curve.h>
#include <uf.h>
#include <uf_csys.h>
#include <uf_part.h>
// UGOpen headers
#include <ug_session.hxx>
#include <ug_part.hxx>
#include <ug_line.hxx>
#include <ug_arc.hxx>
#include <ug_coord_sys.hxx>
#include <coord_sys.hxx>
int main(int argc, char* argv[])
...{
int errorCode;
/**//* Here, we can initialize session using :
1. Open C API environment
2. Open C++ API environment
3. NX Open C++ APIs.
User has to initialize, UG Session using Open C++ as well as NX Open C++, session
also.
*/
/**//* Using Open C API, we can initialize UGSession as follows */
/**//*
errorCode = UF_initialize();
if ( 0 != errorCode )
{
return errorCode;
}
*/
NXOpen::Part *part1;
/**//* Using Open C++ API, we can initialize UGSession as follows */
UgSession::initialize();
/**//* Using NX Open C++ API, we can initialize UGSession as follows */
NXOpen::Session *theSession = NXOpen::Session::GetSession();
/**//* Create a new part.
To create new part one can use :
1. Open C API environment
2. Open C++ API environment
3. NX Open C++ APIs.
*/
char* partName = "InteropWithOpenCOpenCPPAndNXOpenCPP.prt";
/**//* Using Open C API, we can create new part as follows */
/**//*
tag_t UF_partTag;
UF_PART_new(partName,2,&UF_partTag);
*/
/**//* Using Open C++ API, we can create new part as follows */
UgPart *UGPart = UgPart::create(partName, Inches );
/**//* Using NX Open C++ API, we can create new part as follows */
/**//*
NXOpen::NXString partName = "InteropWithOpenCOpenCPPAndNXOpenCPP.prt";
part1 = theSession->GetParts()->NewDisplay(partName, NXOpen::Part::UnitsInches);
*/
//--------------------------------------------------------------------------
// Interop between NX Open C++ APIs and Open C
/**//* Create a line using NX Open C++ APIs*/
NXOpen::Point3d point3d1(-2.17019791346668, 1.13935390457001, 0);
NXOpen::Point3d point3d2(-0.714356813182783, 1.13935390457001, 0);
NXOpen::Line *line1;
line1 = theSession->GetParts()->GetWork()->GetCurves()->CreateLine(point3d1, point3d2);
/**//* Retrieve line coordinates using Open C API */
tag_t line_tag=line1->GetTag();
UF_CURVE_line_t line_coords;
UF_CURVE_ask_line_data(line_tag, &line_coords);
//--------------------------------------------------------------------------
// Interop between Open C++ and NX Open C++ APIs
Point3 UGPt1(line_coords.start_point[0]+5,line_coords.start_point[1]+5, line_coords.start_point[2]+5);
Point3 UGPt2(line_coords.end_point[0]+5,line_coords.end_point[1], line_coords.end_point[2]);
UgLine* UGLine;
UGLine = UgLine::create(UGPt1, UGPt2);
UgCoordSys *UGCoordsys;
UGCoordsys = UgSession::getWCS();
CoordSys Sys = UGCoordsys->getCoordSys();
// Creating Arc
UgArc* OpenCPPArc = UgArc::create(5.0, 0.25, 3.14, Sys);
tag_t arc_tag = OpenCPPArc->getTag();
NXOpen::Arc *nxArc = (NXOpen::Arc*)NXOpen::NXObjectManager::Get(arc_tag);
double nxArc_radius = nxArc->GetRadius();
double nxArc_start_angle = nxArc->GetStartAngle();
double nxArc_end_angle = nxArc->GetEndAngle();
//------------------------------------------------------------------------------------
/**//* Save this work part.
To save this work part one can use :
1. Open C API environment
2. Open C++ API environment
3. NX Open C++ APIs.
*/
/**//* Using Open C API, we can save this part as follows */
/**//*
UF_PART_save();
*/
/**//* Using Open C++ API, we can save this part as follows */
/**//*
UGPart->save();
*/
/**//* Using NX Open C++ API, we can save this part as follows */
/**//* To get the part from the Part tag */
part1 = (NXOpen::Part*)NXOpen::NXObjectManager::Get(UGPart->getTag());
/**//* To save work part using NXOpen automation APIs */
NXOpen::PartSaveStatus *partSaveStatus;
part1->Save(NXOpen::Part::SaveComponentsTrue, NXOpen::Part::CloseAfterSaveTrue, &partSaveStatus);
/**//* To close all parts using NXOpen automation APIs */
theSession->GetParts()->CloseAll(NXOpen::Part::CloseModifiedCloseModified, NULL);
/**//* Terminate the session using Open C API */
errorCode = UF_terminate();
return 0;
}
#include <NXOpen/Session.hxx>
#include <NXOpen/Part.hxx>
#include <NXOpen/PartCollection.hxx>
//#include <NXOpen/Point.hxx>
#include <NXOpen/Line.hxx>
#include <NXOpen/CurveCollection.hxx>
#include <NXOpen/Arc.hxx>
#include <NXOpen/NXObjectManager.hxx>
//#include <NXOpen/NXString.hxx>
//UFunc Headers
#include <uf_curve.h>
#include <uf.h>
#include <uf_csys.h>
#include <uf_part.h>
// UGOpen headers
#include <ug_session.hxx>
#include <ug_part.hxx>
#include <ug_line.hxx>
#include <ug_arc.hxx>
#include <ug_coord_sys.hxx>
#include <coord_sys.hxx>
int main(int argc, char* argv[])
...{
int errorCode;
/**//* Here, we can initialize session using :
1. Open C API environment
2. Open C++ API environment
3. NX Open C++ APIs.
User has to initialize, UG Session using Open C++ as well as NX Open C++, session
also.
*/
/**//* Using Open C API, we can initialize UGSession as follows */
/**//*
errorCode = UF_initialize();
if ( 0 != errorCode )
{
return errorCode;
}
*/
NXOpen::Part *part1;
/**//* Using Open C++ API, we can initialize UGSession as follows */
UgSession::initialize();
/**//* Using NX Open C++ API, we can initialize UGSession as follows */
NXOpen::Session *theSession = NXOpen::Session::GetSession();
/**//* Create a new part.
To create new part one can use :
1. Open C API environment
2. Open C++ API environment
3. NX Open C++ APIs.
*/
char* partName = "InteropWithOpenCOpenCPPAndNXOpenCPP.prt";
/**//* Using Open C API, we can create new part as follows */
/**//*
tag_t UF_partTag;
UF_PART_new(partName,2,&UF_partTag);
*/
/**//* Using Open C++ API, we can create new part as follows */
UgPart *UGPart = UgPart::create(partName, Inches );
/**//* Using NX Open C++ API, we can create new part as follows */
/**//*
NXOpen::NXString partName = "InteropWithOpenCOpenCPPAndNXOpenCPP.prt";
part1 = theSession->GetParts()->NewDisplay(partName, NXOpen::Part::UnitsInches);
*/
//--------------------------------------------------------------------------
// Interop between NX Open C++ APIs and Open C
/**//* Create a line using NX Open C++ APIs*/
NXOpen::Point3d point3d1(-2.17019791346668, 1.13935390457001, 0);
NXOpen::Point3d point3d2(-0.714356813182783, 1.13935390457001, 0);
NXOpen::Line *line1;
line1 = theSession->GetParts()->GetWork()->GetCurves()->CreateLine(point3d1, point3d2);
/**//* Retrieve line coordinates using Open C API */
tag_t line_tag=line1->GetTag();
UF_CURVE_line_t line_coords;
UF_CURVE_ask_line_data(line_tag, &line_coords);
//--------------------------------------------------------------------------
// Interop between Open C++ and NX Open C++ APIs
Point3 UGPt1(line_coords.start_point[0]+5,line_coords.start_point[1]+5, line_coords.start_point[2]+5);
Point3 UGPt2(line_coords.end_point[0]+5,line_coords.end_point[1], line_coords.end_point[2]);
UgLine* UGLine;
UGLine = UgLine::create(UGPt1, UGPt2);
UgCoordSys *UGCoordsys;
UGCoordsys = UgSession::getWCS();
CoordSys Sys = UGCoordsys->getCoordSys();
// Creating Arc
UgArc* OpenCPPArc = UgArc::create(5.0, 0.25, 3.14, Sys);
tag_t arc_tag = OpenCPPArc->getTag();
NXOpen::Arc *nxArc = (NXOpen::Arc*)NXOpen::NXObjectManager::Get(arc_tag);
double nxArc_radius = nxArc->GetRadius();
double nxArc_start_angle = nxArc->GetStartAngle();
double nxArc_end_angle = nxArc->GetEndAngle();
//------------------------------------------------------------------------------------
/**//* Save this work part.
To save this work part one can use :
1. Open C API environment
2. Open C++ API environment
3. NX Open C++ APIs.
*/
/**//* Using Open C API, we can save this part as follows */
/**//*
UF_PART_save();
*/
/**//* Using Open C++ API, we can save this part as follows */
/**//*
UGPart->save();
*/
/**//* Using NX Open C++ API, we can save this part as follows */
/**//* To get the part from the Part tag */
part1 = (NXOpen::Part*)NXOpen::NXObjectManager::Get(UGPart->getTag());
/**//* To save work part using NXOpen automation APIs */
NXOpen::PartSaveStatus *partSaveStatus;
part1->Save(NXOpen::Part::SaveComponentsTrue, NXOpen::Part::CloseAfterSaveTrue, &partSaveStatus);
/**//* To close all parts using NXOpen automation APIs */
theSession->GetParts()->CloseAll(NXOpen::Part::CloseModifiedCloseModified, NULL);
/**//* Terminate the session using Open C API */
errorCode = UF_terminate();
return 0;
}
- Open C、Open C++和NXOpen C++混合开发
- Open C 到 NXOpen 四个关键函数的映射
- open.c
- 谈谈UG二次开发的Open和NXOpen
- open c pkg
- FileStream Open File [C#]
- C语言open()函数
- open.c源代码阅读
- symbian Open C and Open C++ 相关
- C和C++:open("/dev/dcm/0raw",O_WRONLY);
- c/c++ 学习-open 函数
- C语言OPEN函数详解
- C语言OPEN函数详解
- C语言OPEN函数详解
- C语言中open函数
- C语言中open函数
- Open itunes by objective c
- C语言 open函数
- vb6,richTextBox右键弹出菜单问题!!!
- SL 2.0 的SDK / 文档 /控件及单元测试源代码 /blend 2.5 March 2008 Preview
- Div+CSS教程
- 关于业务和IT
- 不要总把一年工作经验当回事!
- Open C、Open C++和NXOpen C++混合开发
- 黑客眼中OpenSSL:强大的密码工具
- DIV CSS网页布局:HTML结构化 DIV CSS网页布局入门指南
- 方法签名
- AHCI介绍
- SQL操作全集
- 一个简单的C#多线程间同步的例子
- CrossFire和SLI
- 12