|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
" y% N2 G- {: O; y7 X7 W7 F
! k: z/ G8 V! Y" r) QNX二次开发源码分享:NXOpen C++创建UDO的过程' e, B. n1 M/ b1 _5 v5 u
% }3 k8 e: e9 m+ }) v& ~9 A7 O0 l5 w+ `; \
UDO的创建是NX二次开发中最高深的一部分内容,通过这个实例,你可以看到如何注册UDO的回调函数,如何创建UDO,定义UDO的编辑,UDO的信息显示等内容!) m7 d, |, |) U( U) D
* Q% Y+ a! D. V5 S( K5 d8 Q
5 X* D/ c( W9 \2 v' B W+ _
8 U; y" n3 A: ^5 ~. `2 k#include <stdio.h>
* {* V- E* X' X) T, |# @#include <string.h>
2 J) v1 {/ Z% R- q& J#include <stdarg.h>9 j; y) J6 p8 a2 T: @
#include <uf.h>
: y9 C( a; u. Q* z#include <uf_ui.h>' P4 i$ t) |1 h$ h- ]
#include <uf_exit.h>4 R: b& @7 K! b
#include <uf_disp.h>
+ p! W, M& a. W0 M! o1 |) | C
7 F1 t" M1 ]& ^. s: G' b5 X* Estatic void ECHO(char *format, ...)
) a& ?( E1 @" G3 d; H, _{
, k1 ?4 E ~3 B char msg[UF_UI_MAX_STRING_LEN+1];5 u* u* @$ m: t$ u; ?. V. k
va_list args;$ l) i8 [) A3 l/ J
va_start(args, format);
/ m; \6 t: z9 T' l vsprintf(msg, format, args);0 s+ f0 y! A& n9 p0 n" J+ f; S* q6 y
va_end(args);! r/ t9 X, {7 K5 F4 u6 k: v8 I/ z
UF_UI_open_listing_window();
) `. e) v! c4 h1 c7 q- U8 E! E UF_UI_write_listing_window(msg);
6 ?: a+ O6 D$ \. D$ K2 Y UF_print_syslog(msg, FALSE);: x2 p2 J$ _$ B! z0 Z S9 E9 N* j
}1 d# t6 e4 C* w
) V6 P2 g$ ?4 H; `- z#define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))
& q( F2 W* U( A5 [
( b9 [+ q5 g& q: Nstatic int report_error( char *file, int line, char *call, int irc)( a; m7 {3 r# e- q3 y
{: `: K+ h8 Z- e$ k: C
if (irc)/ ^ }7 E: p6 U
{8 g% o3 k' U0 ]& |
char err[133];
1 Z/ }+ y. O4 q0 j, S
% B6 U( d, X2 u _( Z0 j m& J UF_get_fail_message(irc, err);
9 K0 g+ T5 d( N9 @. A ECHO("*** ERROR code %d at line %d in %s:\n",
& R* S; z1 j m8 s irc, line, file);6 f# Y3 K2 k4 n3 g
ECHO("+++ %s\n", err);2 y5 M/ _+ d! b" O9 w" ]
ECHO("%s;\n", call);
2 B, E5 j x$ d: Z }* ?5 |7 Z6 L9 H
' S* I/ }+ X8 w4 r. ?& _) s
return(irc);
6 C: i( d* \: F6 r}3 q8 { X8 x4 U. Q4 Y
4 p! N4 }* H2 J0 D0 C8 T% c9 }
#include <NXOpen/Session.hxx> $ O0 w: u6 F/ x* O6 X
#include <NXOpen/Part.hxx>
/ @$ r% X! _, n9 I( B7 ?! M#include <NXOpen/ParTCollection.hxx> ' [3 F; y+ R( y j, m
#include <NXOpen/Callback.hxx>
( o8 t8 \7 ]6 x3 F#include <NXOpen/NXException.hxx>
" T- K2 J8 y: a' H2 V3 z#include <NXOpen/UI.hxx>
' d/ i' D2 ?0 _& L' N0 d#include <NXOpen/Selection.hxx>
/ A K; [' w5 b c4 B) O#include <NXOpen/LogFile.hxx>/ A9 S) Y( |$ v/ W: ^; I$ l5 T2 }5 p, p
#include <NXOpen/NXObjectManager.hxx>8 E" L3 z% k" {9 D
#include <NXOpen/ListingWindow.hxx>2 Y/ A, N' X4 p( D% |- I
#include <NXOpen/View.hxx>
) S6 u. y( M5 D' ^. W7 b( w7 X# Z& c2 k( e' u3 K) S
#include <NXOpen/UserDefinedObjects_UserDefinedClass.hxx>9 y4 p) ^/ Y; _* ^6 O. I
#include <NXOpen/UserDefinedObjects_UserDefinedClassManager.hxx>
4 C& J3 [* y6 g5 A$ f" l. K+ r#include <NXOpen/UserDefinedObjects_UserDefinedObject.hxx>. \+ [, u6 J/ o
#include <NXOpen/UserDefinedObjects_UserDefinedObjectManager.hxx>! }4 s$ J0 y/ l2 W9 v( K8 S. w$ d
#include <NXOpen/UserDefinedObjects_UserDefinedEvent.hxx>1 s& z9 t/ F* q6 ?% v
#include <NXOpen/UserDefinedObjects_UserDefinedDisplayEvent.hxx>$ E0 U; ~# k# v9 Z7 l; [
#include <NXOpen/UserDefinedObjects_UserDefinedLinkEvent.hxx>+ J( `1 t/ o5 A1 x9 G, A* ?/ }
#include <NXOpen/UserDefinedObjects_UserDefinedObjectDisplayContext.hxx>
" G; \& d- e1 m, ]7 G- j! S, B8 i' K5 P Q9 M# x* {
using namespace NXOpen;5 h3 C/ e9 a8 o8 J4 K
using namespace NXOpen::UserDefinedObjects;
' T# L4 M8 D1 e5 `/ |1 o+ n/ y" p. J: O4 d' v+ r
//static variables
4 C! F# ]& K3 \static NXOpen::Session* theSession = NULL;
$ n( _5 L) r) {0 K) Estatic UI* theUI = NULL;
% U9 S; b; b4 o" ~$ Wstatic UserDefinedClass* myUDOclass = NULL;
4 Q7 n) o" }8 t7 F, B% H9 A0 R' L9 q1 _! r& I3 C
//------------------------------------------------------------------------------3 v ~" x6 I% n5 B9 i
// Callback Name: myDisplayCB
" V* ~, Q3 [" h" i: W/ }8 R// This is a callback method associated with displaying a UDO.
5 w" ? F* n$ y3 r( h5 G! Q! B// This same callback is registered for display, select, fit, and attention point4 h0 a5 c+ C: O# p( m
//------------------------------------------------------------------------------
+ M& H2 E+ |; g6 M6 |* U( ~6 yextern int myDisplayCB(UserDefinedDisplayEvent* displayEvent)
! j+ I- }2 w0 E0 d- z{
* m" T1 U; l S0 v try# d3 m' v' d# e7 G
{
8 `7 i- h9 _2 e8 b // Get the doubles used to define the selected screen position for this UDO.
3 t! P4 E- s$ u" Y9 B* R std::vector<double> myUDOdoubles = displayEvent->UserDefinedObject()->GetDoubles();
6 z' v' F q5 e& l
8 E; S' `) l; e ~) H // Use the doubles to define points of a triangle) S1 h- z! M9 ^# ?% s$ Q$ W
std::vector<Point3d> myPoints(4);
3 q1 s3 b, ~- ~( a; @2 x* \6 j" q- t6 c) Y l
myPoints[0].X = myUDOdoubles[0] + 0;0 S& F. P$ m; l$ i2 A; B
myPoints[0].Y = myUDOdoubles[1] + 0;) K% X$ O5 `1 n& J$ \9 ~ I9 \
myPoints[0].Z = myUDOdoubles[2] + 0;
1 V2 n4 _% e o5 N5 ]/ v
, K) N; L8 N. N6 }7 j+ u" s myPoints[1].X = myUDOdoubles[0] + 100;; V; U9 B1 m6 D7 B
myPoints[1].Y = myUDOdoubles[1] + 0;
9 n( w: Q, R8 F myPoints[1].Z = myUDOdoubles[2] + 0;0 D6 y2 g t b% s
* a' m. h% L" y, v myPoints[2].X = myUDOdoubles[0] + 0;
" a& x. i% Z. } myPoints[2].Y = myUDOdoubles[1] + 100;! q! d& M, u1 e' y+ }
myPoints[2].Z = myUDOdoubles[2] + 0;7 Y3 [: t" @& N/ \2 G# p) _
( |: N5 n Z9 X6 f3 q* D2 q, u8 F
myPoints[3].X = myUDOdoubles[0] + 0;
& i1 Q4 J3 M) I8 ? myPoints[3].Y = myUDOdoubles[1] + 0;# L& R0 I. r5 J% C2 x
myPoints[3].Z = myUDOdoubles[2] + 0;
& M- ^" x, Q+ j2 o. K' Q y6 E+ ]; X+ E% H' _) u% g% @
// Display the triangle' G# f* v6 ^9 l" S' e% g/ s
displayEvent->DisplayContext()->DisplayPolyline(myPoints);3 s3 l: d. t4 s6 V" V9 E0 r2 E
7 e2 w, s) d1 Z: P( e/ ~ // Display the text next to the triangle5 X: d" O. H; w6 N) S
Point3d myPt = Point3d(myUDOdoubles[0] + 100, myUDOdoubles[1], myUDOdoubles[2]);! q3 @* y" @) Q: q1 o, e
displayEvent->DisplayContext()->DisplayText("C++ UDO", myPt, UserDefinedObjectDisplayContext::TextRefBottomLeft);
* t4 t) U: |0 F" H( r
E# G' m2 ?8 R7 h // UserDefinedObjectDisplayContext::DisplayFacets fails - see PR 6731653/ f5 \* [0 R" r t( m
// This demonstrates using UF_DISP_display_facets as a work around
4 |3 G# y* s% z, S) u" I8 S. W6 A double normals[9] = { 0,0,1, 0,0,1, 0,0,1 };
$ ?$ }. N$ b( A( U& c double vertices[9] = { myUDOdoubles[0], myUDOdoubles[1], myUDOdoubles[2],
, p$ x$ u! w8 {0 t# b4 C5 {& [! ? myUDOdoubles[0] + 100, myUDOdoubles[1], myUDOdoubles[2],
& p Q3 t' p% G# ~5 O% j myUDOdoubles[0], myUDOdoubles[1] + 100, myUDOdoubles[2] };( Z1 l5 v; q' L4 y
UF_DISP_facet_t facets[1] = { vertices, normals };2 [6 u0 }9 I' [+ v
void *context = displayEvent->DisplayContext()->GetHandle();, J( l( J. ~ r
/ i' _, Q8 A2 a$ n
UF_initialize();" D* N- x6 W9 `8 x, @+ Z% P
UF_CALL(UF_DISP_display_facets(facets, 3, 1, UF_DISP_TRIANGLE, context));
/ H% U0 l _& N( i- W UF_terminate();
$ Z* E7 ?% y7 S# m
* f6 ?; o4 Y+ r1 P }5 q/ d6 K3 B7 ^) \1 ^3 c3 Q) q
catch (NXException ex)
/ k+ q9 f# ~ }9 D0 | {
& b" B+ H" h# _8 \# G# w& T ECHO("CaUGht exception: %s\n", ex.Message());
: [6 F8 l9 `$ J: u0 _5 K }
. c+ s# A9 m5 J- i' v8 T return 0;& X; F5 F$ ~% v& J( W1 D+ F" A
}# ?* u S3 U' X T
//------------------------------------------------------------------------------2 o9 A7 z' S9 Q/ G- X+ Z2 D9 t
// Callback Name: myEditCB
! g* q: ^3 N8 J* w. q// This is a callback method associated with editing a UDO.1 o. n4 `0 v& O8 }( e- N
//------------------------------------------------------------------------------7 y- c( m: T4 [- g* q5 b$ K0 T+ }
extern int myEditCB(UserDefinedEvent* editEvent)
' Q1 f2 B5 l4 Q4 M{
% Y8 y: g/ z% i$ F& E. f try5 g2 t5 z( ?" Z0 D X
{
4 p! n- z3 u" e3 [. f5 s% F( @/ x" n // required for calls to legacy UF routines; x ^' ^* A0 x8 S5 e- h
// such as UF_DISP_add_item_to_display
3 K3 c f% r2 I: J7 G/ [8 Y UF_initialize();
# [$ D. K3 _* n- z9 _9 o" u. _/ q% N0 l
View* myView = NULL;% @8 R6 h) J( G$ ^7 _* p' ~# {
Point3d myCursor(0,0,0);
% f2 ~' P: U, {& h( i" c2 N- x" c) v+ R* _7 Q6 X
// highlight the current udo we are about to edit# j9 y7 d; m4 V0 i7 A5 j5 t
// this is helpful if multiple udo's were on the selection
3 @0 p. F6 i+ V+ b // list when the user decided to edit them
6 Y0 y1 d; d. V editEvent->UserDefinedObject()->Highlight();
$ X* G! E) ]0 v I \$ b7 z6 S8 G% ~) v7 [- j3 F
// ask the user to select a new origin for this UDO
& o& I2 M; V% u$ C8 o) q Selection::DialogResponse myResponse = theUI->SelectionManager()->SelectScreenPosition("Select New Origin for C++ UDO", &myView, &myCursor);' l# y# Y. d- |+ D6 V
// we are done asking the user for input... unhighlight the udo2 i* \: y* J# e% `
editEvent->UserDefinedObject()->Unhighlight();' U% D0 c; r! D2 e1 |* B5 [8 v5 o
, p. |- q% i: o y
// use the new screen position (if the user picked one)! X! T: W, D! R% _2 b. f+ m
if( myResponse == Selection::DialogResponsePick )
! h' a& P: }7 X! k/ N {& s0 c+ z& U1 X1 U9 O9 | q
std::vector<double> myUDOdoubles(3);. [5 z- w; u7 Y- F6 K
myUDOdoubles[0] = myCursor.X;
! R0 r X m6 n! I5 ~( b myUDOdoubles[1] = myCursor.Y;
) |$ j- U7 m- @& x/ n myUDOdoubles[2] = myCursor.Z;
0 o! j/ {5 ]) H // store the newly selected origin with the udo
0 ^8 p E. g, `# C4 d editEvent->UserDefinedObject()->SetDoubles(myUDOdoubles);
5 [& m7 S/ [) Q# t2 B: h // add the udo to the display list manually0 @5 ?7 ]9 z- q1 X2 _0 F7 R! I
// this will force the udo display to regenerate; p& n) ~2 v) k0 K, g
// immediately and show the changes we just made; i& j6 I0 d7 [0 |& T+ P( l" e* c
UF_DISP_add_item_to_display(editEvent->UserDefinedObject()->GetTag());/ q3 k' ^2 M2 [3 K; A7 E3 J
}! {, A; D1 J+ @& Q* {- U
UF_terminate();
K7 @9 Q* h* }) C2 n9 }4 m' X } catch (NXException ex)$ @ S! Q2 [) ]7 y6 M( |
{
+ K, |. |" _% \; H" n ECHO("Caught exception: %s\n", ex.Message());7 I" C o3 ~& h1 T! `
} return 0;
/ J" r/ f# z' n0 [5 C}3 ~& t# o* F+ [% a
//------------------------------------------------------------------------------
) U9 O2 z \7 v" Z) C' f// Callback Name: myInfoCB
. t# W5 u8 A* E4 |4 d [* ^// This is a callback method associated with querying information for a UDO.! A8 H$ Z# O* P
// The information is printed in the listing window.
1 Y, r9 n) v3 b% c! Z//------------------------------------------------------------------------------
6 j Z( F* U1 D A$ [! y( y3 Kextern int myInfoCB(UserDefinedEvent* infoEvent)/ v8 O6 i8 q. j
{
& I# H1 _: j- Y/ S% p7 ?& C/ H3 C. @ try( Q! X. z- w5 `! T: I" Q# _
{3 N+ z+ l$ M9 G, ]+ ~
ListingWindow* theLW = theSession->ListingWindow();/ X: r/ z4 y: g' ^9 w$ ~
char msg[256];
6 H6 L: f7 K' g6 f( H$ j1 U5 g theLW->Open();
1 x. o9 w- l7 f" S+ g& a6 t, E theLW->WriteLine(" ");
3 t- ]6 w( H$ {+ y+ a* t theLW->WriteLine("------------------------------------------------------------");# W: l. S# S% S% @9 p
theLW->WriteLine("Begin Custom Information");
f6 ~# e. R: d+ z6 _. X theLW->WriteLine(" ");0 H$ R r) c' u1 o! Q
sprintf( msg, "UDO Class Name: '%s'", infoEvent->UserDefinedObject()->UserDefinedClass()->ClassName().GetLocaleText() );
6 `4 V* {8 g3 o( V. p theLW->WriteLine(msg);
8 O) |' Y1 S* W sprintf( msg, "UDO Friendly Name: '%s'", infoEvent->UserDefinedObject()->UserDefinedClass()->FriendlyName().GetLocaleText() );
' t; p4 ? k2 k/ A theLW->WriteLine(msg);
6 o) Z; j$ }# H h4 H; F/ f std::vector<double> myUDOdoubles = infoEvent->UserDefinedObject()->GetDoubles();
4 x" D7 r8 Q3 `" o- W/ r' y7 { sprintf( msg, "myUDOdoubles(0) = %f", myUDOdoubles[0] );
0 U* v9 N, \ ]- o! o3 |( s& x9 @ theLW->WriteLine(msg);
( |( l/ x/ |$ [# { sprintf( msg, "myUDOdoubles(1) = %f", myUDOdoubles[1] );$ W1 }. ?4 q! A6 o0 W" V" W3 q
theLW->WriteLine(msg); sprintf( msg, "myUDOdoubles(2) = %f", myUDOdoubles[2] );/ j3 n* A3 { l9 u; R! f
theLW->WriteLine(msg);
i. ~! j3 e1 u% _2 g9 L n theLW->WriteLine(" ");
( _; W! L! y/ Y0 G/ } theLW->WriteLine("End Custom Information");; {$ g( T( ^4 C8 ]; V0 ^" Y
}
* B9 V6 q( S8 |8 N9 \9 A catch (NXException ex)2 G9 R/ b8 U# B/ y& u* P; ^" W! o
{
8 W$ L# o* h0 j" z/ Y1 z- E9 Y R ECHO("Caught exception: %s\n", ex.Message());
$ e$ R( c! v$ @ }
7 C; w# }) s1 K1 M# t, |$ i ~ i return 0;
1 O" @/ n1 j. Z! S, @}/ B" Q* _" _; \# q% s3 {8 Y
- o0 Y) x ~, X+ z$ X7 j8 L c
//------------------------------------------------------------------------------% O" d2 r! o$ d, t9 t
// initUDO
9 N- ^8 e8 Y& P8 {. C// Checks to see which (if any) of the application's static variables are/ ^0 h2 Y% p5 M4 E! j7 W) u
// uninitialized, and sets them accordingly.# E2 q8 q9 ^2 E
// Initializes the UDO class and registers all of its callback methods.
+ r9 Z) z3 j# a7 r4 l* `" C. `//------------------------------------------------------------------------------" j# e0 A6 Q2 P& v! \
static int initUDO( bool alertUser)
) O1 O2 a/ i- Z, N+ L; b9 t3 l{
. v) z m, U# G: F7 e try; u6 q4 K5 G; }) {7 q
{
% J/ _6 A7 u/ a if (theSession == NULL)* k, K+ L v' k
{
& M# D1 J! t" P' y. Q6 t/ o6 d theSession = Session::GetSession();
% _, D5 W7 G \( d }
, d# y$ q6 e6 ?3 ^% E if( theUI == NULL )
+ F$ v: C: }* K# z# X; B3 t4 k {
) d7 ]' t: h* w$ k; O% U theUI = UI::GetUI();" G* g2 E& O4 M+ X" B3 m) b3 y ^
}
" n- I1 g# O7 z$ d2 {3 E6 W5 e if (myUDOclass == NULL)
" e4 ^6 h# [ X4 L2 w {
+ h! w: G- q# v9 ^! j* E2 U if (alertUser)- X9 ~1 D) |6 z& l) g+ m/ C4 l
{4 w$ M: B/ P6 U+ U# j: A6 S4 N! H
ListingWindow*
1 I `* z/ ^& P2 O2 {, _5 I! N theLW = theSession->ListingWindow();
7 A- ~; t$ b: _( r" i) d theLW->Open();- I% W5 [% q0 _% ~; [
theLW->WriteLine("Registering C++ UDO Class");. D, |4 B: J/ ?7 Q( ~0 I
}! e5 p- F: d G# O! _. _
// Define your custom UDO class
) M" ~3 z8 y) e myUDOclass = theSession->UserDefinedClassManager()->CreateUserDefinedObjectClass("Sample_Cpp_UDO", "Sample C++ UDO");; u, f7 X# u$ J& E) W6 p! a
// Setup properties on the custom UDO class
1 N I% P w J- h myUDOclass->SetAllowQueryClassFromName(UserDefinedClass::AllowQueryClassOn);" A* Z. R0 {+ U% k1 h
// Register callbacks for the UDO class
+ O$ ]2 _/ t. N7 M1 c; y& K myUDOclass->AddDisplayHandler(make_callback(&myDisplayCB));; H4 b/ e/ C$ ^( J, D
myUDOclass->AddAttentionPointHandler(make_callback(&myDisplayCB)); w2 ^3 `% N) T1 y
myUDOclass->AddFitHandler(make_callback(&myDisplayCB));
' R9 P) e; M/ y myUDOclass->AddSelectionHandler(make_callback(&myDisplayCB));7 Q, W' i J6 q: g/ Y
myUDOclass->AddEditHandler(make_callback(&myEditCB));# E, @8 B7 M' f& W, x# ~
myUDOclass->AddInformationHandler(make_callback(&myInfoCB));- @# `- r; r6 I) F# Z
// Add this class to the list of object types available for selection in NX.
, i5 l: n; u9 x% }% Z3 f* ^ // If you skip this step you won't be able to select UDO's of this class,. R& Q6 V; U9 C; j6 |2 F' t0 i4 Q
// even though you registered a selection callback.
. ?! P8 G& J9 K' T5 |2 } theUI->SelectionManager()->SetSelectionStatusOfUserDefinedClass(myUDOclass, true);8 T7 S1 s, A8 J$ x# j9 q
}
/ L: j0 w6 W: p$ T' \0 e' ^ }5 T: ~, P1 h& }% ~
catch (NXException ex)7 A! d( `/ B- c! X7 l, u' ~6 x
{) L/ S. J5 H' c) o: r( ^+ N: N8 a
ECHO("Caught exception: %s\n", ex.Message());
2 `5 E3 r8 `1 H6 W }/ c) n$ q T$ h6 f' V
return 0;
' l% B+ \" ?; G9 O1 t}, k E' V4 J- }" c# W
0 X7 ?+ }: Z% H& B$ s0 w- z4 y//------------------------------------------------------------------------------
P0 g1 Y0 Y4 L1 ?// ufusr (Explicit Activation)
" N- z" g* E8 e4 n// This entry point is used to activate the application explicitly, as in
& e$ ]2 [& v$ Q/ s8 J3 z// "File->Execute UG/Open->NX Open..."; S4 f, r* i1 x; }3 a, i7 m
//------------------------------------------------------------------------------6 W E: s2 E9 i. T: I \
extern void ufusr( char *parm, int *returnCode, int rlen )
* _2 ~6 q/ T- q7 W8 |* ]0 {{' f1 \; e: f: `9 j9 y
try5 r) l0 [$ [ D# e( C
{
1 X4 L9 w% x, ~" V) h9 ^+ | // required for calls to legacy UF routines' e/ f5 w& M5 T
// such as UF_DISP_add_item_to_display r$ H* v6 e2 G& Q9 H
UF_initialize();
" Y; A; N5 R5 _( J$ L
' `" N! D6 n' S: f+ R+ S" ]4 n: b9 x // initialize the UDO - if we didn't load this library at- N7 j2 T. l! Y$ ^
// startup, here is our second chance to load it
9 F* q9 e/ T4 G2 H. O3 Q- R initUDO(true);: {7 _7 ~# A, Z/ z! V
; F. d) Z# e1 @* M# J/ y- m. Q/ P" _- { // if we don't have any parts open create one4 N1 i. a, D- K! c: L6 @, s
BasePart* myBasePart = theSession->Parts()->BaseDisplay();7 x; _# s7 i5 M4 s! ]% Q" t6 ], w, P
if( myBasePart == NULL)3 |; L1 a* D- T/ _+ W9 S- ]: v
{; ]0 s5 k% E& x1 g' ^
myBasePart = theSession->Parts()->NewBaseDisplay("test_cpp_udo.prt", BasePart::UnitsMillimeters);/ X. `7 g/ F. p" c, a
}
% S1 f; R% F9 n) ^5 R( m/ `4 r2 U. Q: Q, x. l: N' v* w: ]
View* myView = NULL;
% B" y# ]: Q0 m% k; b Point3d myCursor(0,0,0);
( d0 I! t# U) Y/ s) i% |7 R& \$ R5 [- ~
// ask the user to select an origin for this UDO t2 t1 @- _$ i* n, x
Selection::DialogResponse myResponse = theUI->SelectionManager()->SelectScreenPosition("Select Origin of C++ UDO", &myView, &myCursor);) ]# v( _- o! ~" u( C7 L. G' |
if( myResponse == Selection::DialogResponsePick )3 ~7 r4 d+ k7 Y$ M5 M& k
{
) X# W+ A) B2 L6 U8 x // The user selected a point - go ahead and create the udo
/ p8 [8 T& l6 [$ R& v) y7 T UserDefinedObjectManager* myUDOmanager = myBasePart->UserDefinedObjectManager();2 }5 w! w6 p: i7 e4 E
UserDefinedObject* firstUDO = myUDOmanager->CreateUserDefinedObject(myUDOclass);
7 E, \ Y! Y! {/ n; {7 E+ ~3 ~ // set the color property of the udo - just for fun :) G! o1 }! y/ L' b
firstUDO->SetColor(36);
9 V( T/ F. a ]: s' B) U5 L7 V // store the origin selected by the user with the udo3 z: L' _4 G9 q! {
std::vector<double> myUDOdoubles(3);
1 d8 {8 L [7 k5 M! C: h myUDOdoubles[0] = myCursor.X;$ u% y' s. W( v) i) W8 A4 d
myUDOdoubles[1] = myCursor.Y;
Z4 a+ C4 c2 N- V- J6 ` myUDOdoubles[2] = myCursor.Z;
; A0 v$ s2 e6 W0 l firstUDO->SetDoubles(myUDOdoubles);
7 g+ n* ~" d' r // add the udo to the display list manually
5 N y. F! o x: w: C H: L I$ E // this will force the udo to display immediately
k# T8 a3 M9 X, m$ V) k1 F UF_DISP_add_item_to_display(firstUDO->GetTag());( @ p# A0 j+ B0 |
}
+ m; S6 e: e" l! Q UF_terminate();
4 s3 V0 P" {) t% M( F) r. F }
# a! N! F0 X3 ]& } catch (const NXOpen::NXException& ex)4 k3 x9 A7 s _; ?- O
{
; m5 S! W! G$ A) | ECHO("Caught exception: %s\n", ex.Message());
1 P9 q1 |9 }5 n% ~/ g$ S }
. U8 @6 `% B* {" {; E}- g, p" S( b/ W# g* R2 L
% r5 {' D/ I6 T: H5 |9 X$ T, k5 D//------------------------------------------------------------------------------
9 M! l5 V$ b8 {6 I// ufsta
5 R' s* A0 n- W5 f! ~2 N// Entrypoint used when program is loaded automatically+ k* e' b* G! k& m
// as NX starts up. Note this application must be placed in a
6 X$ c2 M: h2 k. a. r T' t5 ~// special folder for NX to find and load it during startup.' s9 W' o: k( }1 u7 k
// Refer to the NX Open documentation for more details on how$ s1 e" H- G! J+ I% W+ x
// NX finds and loads applications during startup.
+ @: T7 {' O! z$ x) E% p4 f. ?//------------------------------------------------------------------------------
. `. l' f* |; l0 b7 p' qextern void ufsta( char *param, int *returnCode, int rlen )+ u1 ?+ X& ?( S" e" E
{
8 ~# w( a. t7 k0 |' Y6 A# J& k! x; g try, k, x9 O: w5 R7 ?+ m2 h
{
% e, i" m8 @4 V8 u3 V) M initUDO(false);, T- ]" e1 N% f2 b2 j/ s+ W3 {
}8 C% @. i6 c, U2 ]5 r/ j
catch (const NXOpen::NXException& ex)1 h8 [8 s+ p2 {( L
{
5 o' V% n8 Z& f* Y ECHO("Caught exception: %s\n", ex.Message());
! t3 [ ?6 X7 Q- z1 E; V }4 q3 ?6 H2 \' q" P9 h& T9 L
}/ q; m+ \ @* b- D4 \7 j
0 Q. E3 j9 U9 E5 C//------------------------------------------------------------------------------( s) |) }; \9 t: Y+ ?
// ufusr_ask_unload
2 B1 O0 S# N$ a: q// Make sure you specify AtTermination for the unload option.; I' I7 P9 |9 ~! q3 ]/ |- ^* b- ?
// If you unload the library before the NX Session Terminates$ A( T/ Z O/ o' o: L
// bad things could happen when we try to execute a udo4 {. i! |5 P6 R4 V4 \# {) c1 \) o9 Z
// callback that no longer exists in the session.
! I" d* x9 C( H//------------------------------------------------------------------------------
! E' Z$ F6 P3 B2 y+ [extern int ufusr_ask_unload( void ). _- y9 P* F p
{' z# g: m% b9 q, z% ~
return (int)Session::LibraryUnloadOptionAtTermination;9 f) t' Q* O6 a9 S; Y6 Q$ y+ D; z" K: ~
}. y- ?3 V' p! v: [
& @( w0 p( G, L8 _) t( [- Z4 Y2 b# M |
|