• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

OpenC、OpenC++和NXOpenC++混合开发

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

三者的关系我在以前的文章中讲过了。但是他们都不是孤立的,互相可以使用。

下面举了个不同部分用不同的代码,

函数形式的是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;
}

 

原文:http://blog.csdn.net/begtostudy/archive/2008/05/17/2453773.aspx


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Objective-c的@property详解发布时间:2022-07-13
下一篇:
《C陷阱与缺陷》和《C专家编程》两本书又翻印了发布时间:2022-07-13
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap