注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

信息 灵感 创新

I? =Information,Inspiration,Innovation

 
 
 

日志

 
 
关于我

we are 5. Mathematics, Computation, Programming, Engineering, and Making fun of life.

网易考拉推荐

Open C++ Programmer's Guide(5)  

2014-06-18 12:37:51|  分类: UG NX |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
Template Classes

Prior to V18, Open C++ included template classes for character strings (UgString) and dynamic arrays (UgArray). Both were used as input and output from various Open C++ methods. These classes were very similar to the std::string and std::vector classes in the C++ Standard Template Library (STL). In V18, the STL classes std::vector and std::string replaced and obsoleted UgArray and UgString , respectively.

New code written against V18 libraries is advised to use the STL classes directly. The header files ug_vector.hxx and ug_string.hxx have been provided as platform-independent methods of including the STL header files that define std::vector and std::string , respectively.

Old code currently using UgArray or UgString must be modified to compile, link, and run using V18 libraries. We provide the following steps:

  1. The header file ug_array.hxx no longer exists in V18; every instance of this header file in existing code should be replaced with ug_vector.hxx. (The header file ug_string.hxx still exists in V18.)
  2. The classes UgArray and UgString no longer exist in V18; every instance of UgArray may be replaced with std::vector and every instance of UgString may be replaced with std:string. Alternatively, new definitions for UgArray and UgString may be provided if changing the code is not an option. The following definitions should be used:

typedef UgString std::string;
#define UgArray std::vector
UgPart *pMyPart;
// Initialize the pMyPart pointer
// Get the description string for this part
std::string description=pMyPart->getDescription();
// Make sure it isn't a null string
if (!description.empty ( ))
{
??? // do something with it
}

You can also get a C-style pointer to a character array from a std::string object for compatibility with C functions. If description is still a std::string object from the above example, then:

    printf( "Description = %s/n", description.c_str() );

It is important to remember that the C-style pointer from a std::string object must be considered a const pointer; you should not modify the string via the C-style pointer.

Iteration Template Class

You will normally use the UgIterator class to cycle through all the NX objects of a given class.

    // Construct an iterator for NX face objects
    UgIterator <UgFace *> curFace;
    // Loop through all faces
    while (!curFace->isFinished ())
    {
    ??? // Get the name of the current face
    ??? std::string faceName=(*curFace)->getName();
    ??? curFace->findNext();
    }

Note that there are three steps involved in iterating over all objects of a given type:

  1. Construct an UgIterator object. UgIterator is a template class, which means that it is a generic class that can be used to iterate over many different types of NX classes. You identify the specific NX class when you construct the UgIterator object, as in < UgFace * > above. The class must be instantiable. In fact, you will get a compiler error if you try to construct a UgIterator object on a base class such as UgConicObject. The UgIterator constructor also has an optional argument (not used in the above example) that allows you to iterate over objects in a part other than the current work part.

  2. Loop through all the desired objects, one at a time. The while loop is terminated when the UgIterator object returns true from the UgIterator <UgFace *>::isFinished () method.
  3. Inside the while loop, use the * operator on the UgIterator object to acquire a pointer to the current NX object. In the above example, (*curFace) returns a pointer to a UgFace object.

You can similarly use the UgIterator class to find all the NX parts loaded in your current session.

    // Construct an iterator for NX part objects
    UgIterator <UgPart *> curPart;
    // Loop through all loaded parts
    while (!curPart->isFinished())
    {
    ??? // Close this part if it is not metric
    ??? if (!(*curPart)->isMillimeters ())
    ??? {
    ??????? (*curPart)->close ( true );
    ??? }
    ??? curPart->findNext();
    }

  评论这张
 
阅读(545)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2016