UG/open ++ class library for the second development of ug

Source: Internet
Author: User
Tags export class

UG/OPEN ++ class library
Overview
UG/Open ++ has five different classes: Application class, object class, template class, auxiliary class, and mathematics class.
1. Application class:
Control the running of the UG application. Including UgSession, UgInfoWindow, and UgException.
2. object class:
Define the attributes and actions that can act on the objects contained in the UG part file. For example, UgArc, UgFace, and UgExpression. Indicates the UgPart class of the UG part.
3. template class:
Provides platform-independent standard template library (STL) classes, mainly used for arrays and strings. There is also a template class that traverses the UG/Open ++ object.
4. auxiliary classes:
The definition is used as a temporary object in other class definitions. For example, ThruPoint and Evaluator class.
5. Mathematics:
Including general mathematical objects. It is very helpful to use it in combination with the UG object class. Mathematics includes vertices, vectors, matrices, and coordinate systems.
Generally, each class is defined in an independent header file, and the file name is the name of the class. For example, the UgArc class is defined in the ug_arc.hxx file. Sometimes a header file also contains some other class definitions such as helper classes.
In UG/Open ++, you can call a public method of a class without calling its private method. The protection method can only be called in the export class.
● Application
Session)
One of the main functions of the UgSession class is to initialize UG/Open. This Initialization is required before any other UG/Open ++ method is called. The initialization and termination of the dialog period are completed by two static methods: UgSession: initialize () and UgSession: terminate ():
UgSession: initalize ();
// Your UG/Open ++ code
UgSession: terminate ();
Another method is to create an UgSession object:
UgSession mySession (true );
// Your UG/Open ++ code
For UgSession, note the following two points:
1. The UgSession destructor automatically ends UG/Open. This will automatically occur when it is out of the range of the UgSession object.
2. When you use the following syntax to create an UgSession object, the initialization of UG/Open will be blocked, and the Destructor cannot terminate this conversation period:
UgSession mySession;
Functionally, the two initialization methods mentioned above are exactly the same as the traditional UF_initialize () method. You can use either method at the beginning of the program, however, you cannot use two different methods at the same time. In this way, in the following program, the UG/Open ++ and traditional UG/Open methods can be called.
UgSession can also be used to control the status and behavior of the current UG conversation period. For example, some UgSession methods can change the current working part, modify the layer status, and close all parts.
● Object class:
The main definition of the object class can act on the attributes and operations of objects contained in the UG part file. For example, UgArc, UgFace, and UgExpression. Indicates the UgPart class of the UG part. Most UG/Open ++ applications involve operations on UG objects.
There are two types of object classes: base class and leaf class. The base class defines general operations that act on a group of related objects, and they do not have the CREATE () method. A leaf class defines operations on a specific type of object, and most of them define the CREATE () method. The base class represents a group of similar UG objects, and the leaf class represents a specific UG object.
Class System relationships provide a sufficient level of UG functionality, using the base class to define the common operations of such objects. In addition, in some cases, it uses multi-inheritance to define general interfaces of irrelevant objects.
The top-level base class of all UG objects is called UgObject. It defines some general methods that can be used by all UG objects. For example, UgObject: askOwningPart () returns the part of an UG object.
Other base classes are derived from the UgObject class, including UgTypedObject and UgDisplayableObject (note that most base classes in UG/Open ++ end with the keyword 'object ). UgTypedObject provides a method to name or delete an UG object, while UgDisplayableObject provides methods such as changing colors and layers.
Create object
The leaves of the UG/Open ++ hierarchy tree are the C ++ classes that really represent specific UG objects. For example, UgArc represents an arc and UgExpression represents an expression. These classes are called instance classes because the C ++ objects of these classes can be created, and each created object corresponds to a UG object contained in the UG part file. To CREATE a UG object, you only need to call the static method CREATE () for creating the object, as shown below:
UgPart * pWorkPart = UgSession: getWorkPart ();
UgExpression * pExpr;
PExpr = UgExpression: create ("diameter", 4.25, pWorkPart );
Double diaValue = pExpr-> evaluate ();
UG objects are referenced by pointers instead of object names. In the above example, pExpr is used. In fact, the C ++ constructor is a protection method, which can avoid calling the constructor incorrectly in an inappropriate place. Pointer Reference reduces memory usage and ensures that the written C ++ code is synchronized with the UG model at any time.
The UgAssemblyNode class is a leaf class without the CREATE () method. This class of object is created using UgPart: addPart ():
UgPart * pWorkPart = UgSession: getWorkPart ();
UgAssemblyNode * pNode;
PNode = pWorkPart-> addPart ("component. prt", "", "", CoordSys (),-1 );
Some classes cover static CREATE () methods, while other methods are used to create ug objects.
The following describes three methods to create an expression:
UgPart * pWorkPart = UgSession: getWorkPart ();
UgExpression * pExpr1, * pExpr2, * pExpr3;
UgString strName ("diameter1 ");
PExpr1 = UgExpression: create ("radius", 4.25, pWorkPart );
PExpr2 = UgExpression: create ("diameter = 2 * radius", pExpr1 );
PExpr3 = UgExpression: create (strName, "2 * radius ");
The last parameter of all the create functions is an option parameter to specify the part context, that is, the host part of the newly created object. If this parameter is not specified, it belongs to the current working part. This parameter can be a pointer to a part object or to other objects belonging to the part object. For example:
UgPart * pOtherPart;
// Initialize pOtherPart to point to an available UG part object
Ugexpression * pexprnew;
Pexprnew = ugexpression: Create ("length = 3.0", potherpart );
Permission Control
When a pointer to an ug object is defined, it can be used to call the method defined by this class and its parent class. For example, if Parc is a pointer to ugarc, you can call the Parc method to query or modify the ug arc object. The Code is as follows:
Parc-> setradius (2.5 );
Double Len = Parc-> computearclength ();
Int layer = Parc-> getlayer ();
In the preceding example, all three methods can be called by the ugarc object. However, only the setradius () method is defined in the ugarc class. The other two methods are defined in the parent class.
Sign and pointer Conversion
UG/Open ++ allows the development code to contain the traditional UG/Open code and transmit relevant data. This requires conversion between the pointer of UG/Open ++ and the mark of UG/Open. The ugobject: Find () and ugobject: gettag () methods can complete this type of conversion. Ugobject: Find () returns a pointer to the ugobject object. Therefore, forced type conversion is required (see the dynamic type conversion section ). For example:
Int color;
Tag_t tag1, tag2;
// Call the traditional UG/Open function to select a line.
// Note: This returns the tag of the selected line as 'tag1'
Uf_ui_select_single (..., & tag1 ,...);
// Use the 'Find 'method to get the pointer of the Unigraphics
// Object corresponding to 'tag1'
Ugobject * pobj = ugobject: Find (tag1 );
If (pobj)
{
Ugline * pline = dynamic_cast <ugline *> pobj;
If (pline)
{
// Invoke a UG/Open ++ method using that pointer
Pline-> setcolor (red );
// Now convert the pointer back to a tag ('tag2 ').
// Note that 'tag1' and 'tag2' should be identical.
Tag2 = pline-> gettag ();
// Call a traditional UG/Open function to get the color
// Using 'tag2'-It shoshould be red.
Uf_obj_ask_color (tag2, & color );
}
}
As shown in the preceding example, if a UG object does not have a creation method, the ugobject: Find () method may return 0. Therefore, in general, it is necessary to check the pointer returned by ugobject: Find () and perform forced type conversion. This ensures no errors.
Parts
The ugpart class defines the ug part method, including creating a new part, opening an existing part, saving the part, and closing the opened part. It should be noted that the method for closing a part belongs to the ugpart class, and the method for closing all parts belongs to the ugsession class. The ugpart class also contains methods for reading and Modifying part attributes and other data stored in part files. For example,
Ugpart * Ppart = ugpart: open ("valve. PRT ");
// Find out what the part units are
Bool isitmetric = Ppart-> ismillimeters ();
The ugpart: iteratefirst () and ugpart: iteratenext () methods provide a mechanism to traverse all the ug objects stored in the part. First, ugpart: iteratefirst () is called and the first object in a part is returned. Then, by constantly calling the above ugpart: iteratenext () method with the accessed object as the parameter, the traversal process continues until all objects are accessed. In this case, ugpart: iteratenext () returns 0. For example:
Ugpart * pworkpart = ugsession: getworkpart ();
Ugtypedobject * pcurobj;
For (pcurobj = pworkpart-> iteratefirst ();
Pcurobj;
Pcurobj = pworkpart-> iteratenext (pcurobj ))
{
Ugstring name = pcurobj-> getname ();
}
Note that, because this Traversal method can access various types of objects, a pointer to the base class UgTypedObject is returned. Then, only the methods defined in the class UgTypedObject can be called, such as reading object names and attributes. If you want to call a method defined by a specific class, you must forcibly convert the type.
Another Traversal method is defined by the template class UgIterator, which will be discussed in the template class section later.
Prototype and instance
The concept of UG original model and instance is mainly used to access and manipulate UG objects in assembly. A prototype refers to a specific geometric object in a component, and an instance defines the position and orientation of the prototype object in the Assembly. When you use UG/Open ++ to traverse a UG object, you may access the prototype and instance of an object at the same time. If a prototype object is accessed, you can read and modify it. However, if you access an instance object, you can only perform read operations. Direct modification is not allowed. Whether you are accessing a prototype object or an instance object, you can modify it in the following ways:
UgLine * pLine;
// Initialize the pLine pointer
Point3 newPt;
...
// Set the end point of the line to (0.0, 0.0, 0.0)
(PLine-> askPrototype ()-> setEndPoint (newPt );
NOTE: If pLine is an instance object, UgLine: askPrototype () returns the corresponding prototype object. If it is already a prototype object, it returns itself.
The following example shows how to determine whether an object is a prototype object or an instance object:
UgLine pLine;
// Initialize the pLine pointer
...
If (pLine-> isOccurrence ())
{
// It's an occurrence
}
Else
{
// It's a prototype
}
Curves and Boundaries
UG treats the border curves of common wireframes and entities respectively. However, in terms of development, the class hierarchy of UG can also process them with the same code. Since both the line box curve and the Object Boundary are based on gEvaluatableObject, you can use the same method for processing. In the following example, when calculating the arc length and finding the intersection between the arc and other objects, encoding is not required for the type test.
UgEvaluatableObject * pObj1, * pObj2;
// Assume the user selected pObj1 and pObj2 so you don't know
// Their types (I. e. the user might have selected an edge
// And a wireframe curve)
// Get the arc length of each object, regardless of type
Double len1 = pObj1-> computeArcLength ();
Double len2 = pObj2-> computeArcLength ();
// Compute the intersection points for these two objects
UgArray <CurveCurveIntersectionPoint> iPts;
IPTS = pobj1-> computeintersectionpoints (pobj2 );
In addition, you can use the evaluatableobject: askevaluator () method to return the evaluator object to access the coordinates and normal vectors of any point in the solid boundary and line-frame curve.
The method mentioned above is applicable to objects of the evaluatableobject type, such as straight lines, arcs, straight line boundaries, and curve boundaries. No type check is required. In other cases, you may need to access more specific object information, for example, to obtain the radius of an arc object, but you do not know whether the object is a dashed arc curve or an Arc Boundary of the object, in this case, you can use the following method, instead of performing type checks:
Ugevaluatableobject * pcircularobj;
// Initialize pcircularobj to some circular object,
// But not know whether it is a wireframe arc or
// A circular Solid Edge.
// Get the generic curve object for it. The dynamic cast
// Shocould work since we know we have an arc or circular edge.
Arc * Parc = dynamic_cast <arc *> pcircularobj-> askcurve ();
// Now we can do specific inquiries on it
Double Radius = Parc-> getradius ();
● Template class
The UG/Open ++ template class is mainly used for processing strings (ugstring) and dynamic arrays (ugarray. Strings and arrays are frequently used as input and output parameters of the UG/Open ++ method. They are very similar to the string and vector classes in the C ++ Template Library (STL. An obvious difference is that the STL class provides the Traversal method, while the UG/Open ++ class does not. Because ug does not fully support STL, the corresponding STL class cannot be used in UG/Open ++. This may be implemented in future versions. See the following example:
Ugpart * pmypart;
// Initialize the pmypart pointer
// Get the description string for this part
Ugstring description = pmypart-> getdescription ();
// Make sure it isn' t a Null String
If (! Description. Empty ())
{
// Do something with it
}
To be compatible with C language functions, UG/Open ++ also allows the use of ugobject objects to return string pointers that conform to the C language syntax. If the description in the above example is a ugstring object, the following code is correct:
Printf ("Description = % s/n", description. c_str ());
It is worth mentioning that such pointers can only be used as pointer constants, so they cannot be used to modify strings.
Traverse template class
Generally, the ugiteration class is used to traverse a group of similar objects. For example:
// Construct an iterator for Unigraphics face objects
UgIterator <UgFace *> curFace;
// Loop through all faces
While (! CurFace-> isFinished ())
{
// Get the name of the current face
UgString faceName = (* curFace)-> getName ();
CurFace-> findNext ();
}
It generally takes three steps to traverse all these similar objects:
1. Create a traversal template object. UgIteration is a template class, which means you can traverse different types of UG classes in the same way. When creating an UgIteration object, you must specify the specific UG type, for example, in the previous example (UgFace *). This class must be instantiated. Therefore, if you want to create an UgIteration object for a base class of UgConicObject, an error will occur during compilation. The UgIteration constructor has an optional parameter (not used in the previous example), which allows you to traverse objects not contained in other parts of the current Working part.
2. cyclically access all objects to be accessed. Only one object can be accessed at a time. The While loop ends when the UgIterator <UgFace *>: isFinished () method of the UgIteration object returns true.
3. In the while LOOP, apply the * operator to the UgIterator object to obtain a pointer to the currently accessed object. In the preceding example, (* curFace) returns a pointer to the UgFace object.
You can also use the UgIterator class to access all the UG parts loaded during the current dialog period in the following way.
// Construct an iterator for Unigraphics 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 ();
}
● Auxiliary class
UG/Open ++ contains many helper classes. They are mainly used to transfer data back and forth for methods defined in other classes. For example, ThruPoint is generally used to specify the position, slope, and curvature of any point in the UgSpline curve. As follows:
UgSpline * pSpline;
// Initialize pSpline pointer
UgArray <ThruPoint> thruPts; // Array of ThruPoint objects
UgArray <double> params; // Array of doubles
Bool periodic;
Int order;
// Get defining data for a spline
PSpline-> getThruPoints (& periodic, & order, & thruPts, & param );
Note: unlike other UG classes, the name of the auxiliary class does not start with the letter UG.
● Mathematics
The vmathpp library contains common mathematical operations. Processing of vertices, vectors, and matrices. These class objects are very useful when calling the UG object method. Many standard operations in mathematics have been overloaded to make the code simpler and easier to read. For example,
Point3 pt1 (0, 2, 4 );
Vector3 offset (1, 2, 3 );
Point3 pt2 = pt1 + offset;
UgLine * pLine = UgLine: create (pt1, pt2 );
Another important aspect of the vmathpp library is that the class it contains is completely independent of the UG. It can also be called in other applications unrelated to UG.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.