PLM之家精品课程培训,联系电话:18301858168 QQ: 939801026

  • NX二次开培训

    NX二次开培训

    适合初级入门或想深入了解二次开发的工程师,本培训结合ufun,NXOpen C++,大量的实例及官方内部的开发技术对于老鸟也值得借鉴!.

    NX CAM二次开发培训报名 NX二次开发基础培训报名
  • PLM之家Catia CAA二次开发培训

    Catia二次开发培训

    Catia二次开发的市场大,这方面开发人才少,难度大。所以只要你掌握了开发,那么潜力巨大,随着时间的积累,你必将有所用武之地!

  • PLM之Teamcenter最佳学习方案

    Teamcenter培训

    用户应用基础培训,管理员基础培训,管理员高级培训,二次开发培训应有尽有,只要你感兴趣肯学习,专业多年经验大师级打造!

  • PLM之Tecnomatix制造领域培训

    Tecnomatix培训

    想了解制造领域数字化吗?想了解工厂,生产线设计吗?数字化双胞胎,工业4.0吗?我们的课程虚位以待!

PLM之家PLMHome-国产软件践行者

[二次开发源码] NX二次开发源码分享:动态画圆,指定屏幕点和向量相关用法

  [复制链接]

2016-9-17 10:11:08 6233 2

admin 发表于 2015-2-9 13:45:19 |阅读模式

admin 楼主

2015-2-9 13:45:19

请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!

您需要 登录 才可以下载或查看,没有账号?注册

x
" G. W' }1 D; C5 R* Q8 M  Q
NX二次开发源码分享:动态画圆,指定屏幕点和向量相关用法
' d. R) Y' _& v$ u: @: E, @% }# F: j1 Y% G
" l3 r1 k2 U  H5 f0 Y
这个案例很不错的,分享下,程序运行的结果是指定屏幕,拖拉即可动态绘制圆圈!
# _& \# O1 _6 b1 x. b3 F% K2 W4 f1 u' v3 M1 y. B
#include <stdio.h>
4 m$ A( `- ^6 w) O$ F' i; f1 r#include <uf_defs.h>
, R- |6 T9 k4 b: n. J# ?#include <uf.h>3 t  v$ [1 F4 t$ S* L3 x+ g
#include <uf_ui.h>! @* D: X0 A2 m2 t
#include <uf_csys.h>6 J4 i' N6 y% H' a  g
#include <uf_vec.h>3 ^% s8 C6 _' B4 K) J
#include <uf_disp.h>: W1 c9 s; X3 T! T4 l+ m
#include <uf_curve.h>
2 i: }$ G$ n/ }7 i( \#include <uf_mtx.h>1 r; R1 d% z" t
#include <uf_obj.h>% Q% K! L7 H6 ?
typedef struct
+ B" D' ]+ W( ~& n        { UF_CURVE_arc_t  *arc;4 e  M; `3 K" K+ y
          double          abs_ctr[3];/ Q$ n* h- B* [+ y% j* ?; ]( Q; S
          double          matrix[9];
5 M4 D% z" F* b1 r' s* `9 O          double          x_axis[3];4 v7 a$ i4 J. I4 T: j) r" A( V, c& `
          double          y_axis[3];7 }. E. r& n6 t
        } my_motion_data_t;' \3 Q5 I! b0 e, |) e
/* Define a motion callback to render a visual representation of
: j0 C4 b# |+ _* L6 y * the circle to be created, along with a bounding box around the8 P6 ~- Z" b7 e5 K  z* y" [
* circle, an arc of radius 1.0, and a "rubberband" line from the5 X% C$ `! O; W2 d6 s1 v- U
* center to the cursor position.
/ }* h2 |: W, W( ]& N */& \8 R: `5 A* [& m) P( L+ [7 B
static void motion_cb( double                   *screen_pos,. T* O1 B. W4 Z+ W
                       UF_UI_motion_cb_data_p_t  motion_cb_data,
7 n) l4 `" _5 J" n( B                       my_motion_data_t        *my_data )
$ t7 ~( x# q$ S: I9 I{$ G* v; I  U9 b0 V! @8 q
    double radius, pos_array[5][3];
, B, u" H1 I$ I+ M# v5 ?. N    double xrad[3], yrad[3], x_y_vec[3], x_ny_vec[3];
, J) F! O8 S! P% ~    /* Calculate the arc radius:  the distance from the arc center
4 @- j. P# H& b" N     * to the current screen position.
; E/ v$ F5 T; P' D     */, H. |0 u3 N0 k3 }; b8 E
    UF_VEC3_distance( my_data->abs_ctr, screen_pos, &radius );
- U6 g0 o$ }4 c% y# o$ r, K/ }  f' g' B    /* Map the arc center to the "csys of the arc".
; H9 v& X: k  y7 l- N9 E     */
5 I5 g3 @) j1 N" [0 t- d; ]( j    UF_MTX3_vec_multiply( my_data->abs_ctr,
0 D- L- f2 \7 x' Y3 w                       my_data->matrix," L& w' [2 u0 n8 H* Y
                       my_data->arc->arc_center );$ d0 W/ z1 B! P# q) X! Y; c- J9 O
    /* Draw a circle and an arc in the view of the cursor.9 t$ w, ?& s% V! D3 X
     */. Y5 J8 M# q1 B. T) ~
    UF_DISP_display_ogp_circle( motion_cb_data->view_tag,8 p- {$ s  B7 M/ s, W
                            my_data->matrix,
0 \3 u; t! A9 X                            my_data->arc->arc_center,
3 L) k! `( y6 L9 X+ m# a( v3 z8 N                            radius );: c% {" A% v" X9 W4 y) s9 b+ e% s
    UF_DISP_display_ogp_arc(    motion_cb_data->view_tag,/ _- k; ?) E+ U
                             my_data->matrix,; w# d* p% S/ ~- `
                             15.0*DEGRA, 345.0*DEGRA,3 w# S- m' ]8 K1 v1 h8 P+ H
                             my_data->arc->arc_center,
) h% T# k0 u& @  r                             1.0 );, ]6 P8 j9 W, t/ D" S1 e  s
    /* Draw a bounding box around the circle.9 m% A* E. H4 x$ U
     */3 H# H2 b0 z, i" S! N, ]
    UF_VEC3_scale( radius, my_data->x_axis, xrad );
) b8 e- P9 C0 A+ g' J* o    UF_VEC3_scale( radius, my_data->y_axis, yrad );+ E5 }9 ?* S8 w1 U
    UF_VEC3_add( xrad, yrad, x_y_vec  );
8 G5 N5 T# ^' G, G" K    UF_VEC3_sub( xrad, yrad, x_ny_vec );, R% v6 n4 V3 i6 ~
    UF_VEC3_add( my_data->abs_ctr, x_y_vec,  pos_array[0] );) C$ A+ f% _) X' _
    UF_VEC3_sub( my_data->abs_ctr, x_ny_vec, pos_array[1] );
3 G8 X3 o8 P" A3 B* G; P' j+ k    UF_VEC3_sub( my_data->abs_ctr, x_y_vec,  pos_array[2] );% {9 ^, g( E. x0 O. W! o8 ?
    UF_VEC3_add( my_data->abs_ctr, x_ny_vec, pos_array[3] );5 g% t' v) n$ b; a4 a" `& n& y' |
    UF_VEC3_add( my_data->abs_ctr, x_y_vec,  pos_array[4] );  t* J1 L3 O  M/ C, M  X0 s, y' H% D
    UF_DISP_display_ogp_polyline( motion_cb_data->view_tag,: g6 B! S5 B# V: U
                              pos_array, 5 );1 m  m3 A8 r/ {
    /* Draw a "rubberband" line from the circle center to the2 h$ Q% Z6 O. l# h
     * cursor position.+ Y' p! r5 G* \1 m, s, P
     */
0 y7 B# ]+ K' A: n5 M; @5 ^5 w    UF_DISP_display_ogp_line( motion_cb_data->view_tag,
, `9 b7 S8 d& v; J: s                          my_data->abs_ctr,9 t/ ~3 m( Z; z3 h9 p/ ?7 \
                          screen_pos );
& u6 ]2 X& J( v! P( s0 |- c# g}) N. L; r3 R$ {- Q- v: x# N" [
#define UF_CALL(X) (report( __FILE__, __LINE__, #X, (X)))
# Z9 N; J" s# X. F0 d5 Pstatic int report( char *file, int line, char *call, int irc)4 b- }  P7 R' t) H# L7 V
{) a, R5 N7 e" H  c* _
  if (irc)
0 t& t! ]7 A, F3 |$ h+ C; K5 g  {
( E! Y7 S9 ?3 D  Z# O' x     char    messg[133];7 r  E: U9 P1 q$ d0 B
     printf("%s, line %d:  %s\n", file, line, call);) m& D2 E0 h' f3 v! h7 ]8 d
     (UF_get_fail_message(irc, messg)) ?
/ }, |  Y* O/ q$ h) ^7 B       printf("    returned a %d\n", irc) :; ^; @8 T1 [4 c3 v
       printf("    returned error %d:  %s\n", irc, messg);0 Z0 p" l) }  d: }% I/ M) D4 p+ {
  }
6 _/ h# [* W4 o& x  [. H- k  return(irc);
, x9 Z" ?. }4 w* |; e7 F$ Y}1 Z8 h  r; K, x/ ~1 y# Z3 E
static void do_UGopen_api(void)) ]$ m, c$ y6 K& e" P* q/ L
{% ?5 t2 G/ t1 n# i
    int               default_plane;2 [6 L) {5 u' Y+ ~1 }1 `
    int               plane_resp, ctr_resp, pos_resp;" a% a$ O! n3 q' J- }" [+ N/ R6 K
    tag_t             plane_tag, saved_wcs, mtx_id, csys_id,* y- N8 r# J$ Y) ?/ r( W$ k
                      arc_id, view_tag;/ e8 T) O0 U3 t
    double            plane_matrix[9], plane_origin[3],! t7 r! a' }- S8 R' Z7 `
                      x_vec[3], y_vec[3], arc_edge_pos[3];6 m8 C; U' m) z* R; o5 B& [: J- ]$ q, e
    double           root_origin[3] = {0.0, 0.0, 0.0};! J. r, w( ]: }* u& t3 }
    double           work_origin[3];( y0 t6 s& m& ~  d* `/ D
    UF_CURVE_arc_t    arc;# F" m4 {. Z1 q+ o1 @, c
    my_motion_data_t  my_data;0 W' }5 S2 e2 {( U: b- O7 G. w
' d: Z, N3 G$ g. v
    my_data.arc    = &arc;. d3 p+ Y4 c4 i: ?  Y  ^7 ~
    arc.start_angle =   0.0;
8 Y3 R1 k9 _2 s  |. L2 Y# j! ^5 J1 W    arc.end_angle   = TWOPI;    /* Create a full circle. */: Z" f1 u1 f' E! c' Q7 A7 X
    default_plane   = 5;       /* Default plane = WCS */
- b* D+ f* Z5 Z4 ~    do: g# g: B- G( F4 X3 Z$ r6 h$ i
    {
4 e" }5 u2 X3 R, t0 T: n/ g        /* Specify the plane on which the circle is to be created.) I5 g) k1 R# w3 H7 D
         */
4 u7 u: I& I$ y8 G9 u4 G; x        UF_CALL(UF_UI_specify_plane(
) O* Q) W  m/ k7 h/ D+ J, m' [                         "Specify plane for circle creation",7 ^# @7 t1 m% S: ^3 |
                         &default_plane,
% Q9 Y, m$ C4 c) a' W& Q3 i                         1,
. T& f; I6 X7 K! z                         &plane_resp,
2 V8 I8 n5 w& K1 }7 t2 n' H                         plane_matrix,
  `/ P% G8 N8 k) z) @% I4 ^; V                         plane_origin,
( P4 a) [/ B9 p9 W' X- k- X                         &plane_tag ));
3 \% i8 u' O) x+ n        if (plane_resp ==3)
$ v4 `6 ?) O1 s% H# \" E: e        {
+ z5 M! ~- [5 |! `            /* Save the current WCS for future restoration.* s, {) _: {8 t5 A/ f+ `. r
             */! r1 y) [  f0 A8 B: H) v# x- ~
            UF_CSYS_ask_wcs( &saved_wcs );
! D8 E5 w: Z& P& k. X  a' Q& M) U            /* Move the WCS to the specified plane. This is
4 Z2 A! s: t, [- I$ D" A             * necessary because the position passed to the motion# X0 T7 @6 m. {& `, P3 l
             * callback, and the position returned by
1 v- ?# K% Z$ X# h, q             * UF_UI_specify_screen_position, is the screen
; q* I5 r# l9 ^5 w, O7 j8 @             * position projected onto the WCS XY plane.
8 r1 U. _, |/ Q5 E4 R# B             */* n+ w# U; ]5 Y9 f. L
            if (default_plane != 5)0 o* r6 a( H4 c" C& s2 `6 g, ]
            {8 v- f) [" G- ]$ V, h, f6 O2 ^! F: ?
                UF_CSYS_create_matrix( plane_matrix, &mtx_id );
7 I8 ~0 Y+ t4 o                UF_CSYS_create_csys(  plane_origin, mtx_id,1 ?+ F" i% ?7 q; N8 j, x6 c
                                   &csys_id );( i! Y/ j. G% `! X' i; M
                UF_CSYS_set_wcs( csys_id );  K; M3 c* k: z7 j
            }) W4 P% ?8 X9 T& `1 Q
            /* Obtain unit vectors and the arc matrix relative to
$ x1 b9 O" ^' ~7 k: w: T             * the Work Part coordinate system.$ f7 V% [' w1 c6 ~7 `! ~
             */
6 r7 h: `7 G- y            UF_MTX3_x_vec( plane_matrix, x_vec );
0 W$ l" u( N- d            UF_MTX3_y_vec( plane_matrix, y_vec );+ s) ~# _$ z2 z# f8 c  n
            UF_CSYS_map_point( UF_CSYS_ROOT_COORDS, x_vec,
6 p' f" c. @" {$ p; j6 `1 r" l! i- z                            UF_CSYS_WORK_COORDS, x_vec );: |- r6 w! |: Z. m
            UF_CSYS_map_point( UF_CSYS_ROOT_COORDS, y_vec,
2 H' S; V) s% P, C- p( j: f5 v                            UF_CSYS_WORK_COORDS, y_vec );
! r9 Z" X% a( F  X. G            UF_CSYS_map_point( UF_CSYS_ROOT_COORDS, root_origin,
; W& u6 R0 |& X& U& _) n- C8 W                            UF_CSYS_WORK_COORDS, work_origin );6 p) a- X8 Y# s% _
            UF_VEC3_sub( x_vec, work_origin, my_data.x_axis );% C! Q( a& Y) w8 z% `5 E, O
            UF_VEC3_sub( y_vec, work_origin, my_data.y_axis );
# r, Z/ R, V: s            UF_MTX3_initialize( my_data.x_axis, my_data.y_axis,( A  z6 a0 n  S# }
                             my_data.matrix );
- I  F" e4 P2 X# @            UF_CSYS_create_matrix( my_data.matrix,
! ]% N: T$ k! a+ W4 W8 m+ T+ C                                &arc.matrix_tag );' t$ |; k8 s$ t4 {  `- N
            do" r0 T/ T, c) u6 m% |  y4 j
            {, m% v; Z1 N0 ^1 c6 m+ M
                UF_CALL(UF_UI_specify_screen_position(
) g8 I; G! V( y& F$ f7 m1 F; E                                "Specify arc center",' ~( u) n1 n6 H1 [& J4 c
                                NULL,
) {' W; O/ f3 X  \                                NULL,) n$ u& ]; }3 L4 O% _# b( c* z
                                my_data.abs_ctr,
' W3 c9 t% y( E+ O                                &view_tag," x. k+ n2 L, o+ o
                                &ctr_resp ));7 j9 V# S( N* k, N" x! d
                if (ctr_resp == UF_UI_PICK_RESPONSE)2 [1 C7 X/ x, p
                {3 p; ^7 L) t" g, j6 i
                    /* Map the arc center to the arc csys.
: K  e% [0 @1 d) g1 V* N# e. s+ _                     */
, \7 ]8 [1 w, t( b                    UF_MTX3_vec_multiply( my_data.abs_ctr,5 ^3 L: S) `: W1 b5 j+ B0 _0 ]  ]% m
                                          my_data.matrix,; i/ }2 F8 @$ \+ F
                                          arc.arc_center );' q) f% g# @) R9 o  u8 k  ^
                    UF_CALL(UF_UI_specify_screen_position(
8 S5 T; J6 m- {& u/ [, D                                    "Indicate arc radius",
9 n0 i( Y, g7 s                                    (UF_UI_motion_fn_t)motion_cb,
& b5 w- y- }$ I  M8 T9 l! Y, y                                    (void *)&my_data,
6 {9 u8 L2 L6 H# H. c  m                                    arc_edge_pos,
; o3 x. m2 i" f                                    &view_tag,
' E! }! o# _) i3 v                                    &pos_resp ));
) J! b7 C' p& V0 G/ s: c                    /* If a position was obtained, create the
& h( r5 i8 n% O" k+ ~3 g                     * circle.8 e+ {( b  P; y8 k( f4 p: B
                     */
; J, v% f; j3 c* S* ^. K, @$ p                    if (pos_resp == UF_UI_PICK_RESPONSE)
- E) Q. [5 q) b; S/ ^% E* {/ H                    {
9 D. Q: u; ?1 X5 T# V  J3 V6 J                        UF_VEC3_distance( my_data.abs_ctr,
% X2 |+ q& F6 _2 @8 D                                        arc_edge_pos,
; `$ J' ~. I& D4 j: z6 t                                        &arc.radius );
: `) C/ k) D" O- c( ]! Y# h                        UF_CURVE_create_arc( &arc, &arc_id );
0 o! K% e1 z$ D9 D7 I  d                    }' {: m7 u* t& I
                }( {# N2 K/ F# G9 ?) a
            } while ( (ctr_resp == UF_UI_PICK_RESPONSE) &&
" `* X5 V8 U4 c/ ?% ?" U9 S                     (pos_resp != UF_UI_CANCEL)           );
8 b& |1 d) f" Q, C' I            /* Restore the WCS if it was altered above.! A3 f) m) o$ l5 x
             */4 c5 V: O$ h0 h# h3 O8 L( _% _
            if (default_plane != 5)+ V6 ~: d; r( A6 }& q2 r
            {1 @5 c$ h4 v' Q3 L
                UF_CSYS_set_wcs( saved_wcs );9 c! \5 o8 v- x$ h+ T8 [! [
                UF_OBJ_delete_object( csys_id );$ @5 u" C6 R+ F& ]3 p
            }
; \+ H0 Z' @  w% P9 p9 p8 |9 [# ~8 j        }2 }6 D% C- ~$ f. g2 T0 R: I8 \
    } while (ctr_resp == UF_UI_BACK && plane_resp == 3);  b2 w# @& l0 o9 d; ~
}
; W* }, H" S/ i6 P- u" X; q/*ARGSUSED*/
9 n# Q0 @: l8 Y- D( R0 a0 G) X0 vvoid ufusr(char *param, int *reTCode, int param_len)
9 p( S" {* C9 d1 q{
2 P6 K, }( P) V4 g8 |  if (!UF_CALL(UF_initialize()))
" [4 q9 \; k; u  {) n+ X! Z  J3 y; K# V% u
    do_ugopen_api();8 U( j: v9 r6 D+ B+ d
    UF_CALL(UF_terminate());9 I6 h& ]; Q9 j% C% U
  }
5 W, A* o8 V* H* T. U# ^# L}& L( q& m) |( `7 }) g& u7 K
int ufusr_ask_unload(void)# K, X2 G0 c  j+ l: Q& s  w
{) i- s4 o8 j( w
  return (UF_UNLOAD_IMMEDIATELY);5 B; _- L) @" a8 A& X
}
3 N( \( T- M7 b) w
) v* F) A5 l& |7 C6 z6 C8 w) K+ S
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.diantuankj.com/ doTeam.tech
回复

使用道具 举报

全部回复2

yuleihz 发表于 2016-1-8 22:21:57

yuleihz 沙发

2016-1-8 22:21:57

老师来个NXOPEN的耍耍
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.diantuankj.com/ doTeam.tech
回复 支持 反对

使用道具 举报

wu150060 发表于 2016-9-17 10:11:08

wu150060 板凳

2016-9-17 10:11:08

学习一下,顶( }
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.diantuankj.com/ doTeam.tech
回复 支持 反对

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 注册

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

    本网站(plmhome.com)为PLM之家工业软件学习官网站

    展示的视频材料全部免费,需要高清和特殊技术支持请联系 QQ: 939801026

    PLM之家NX CAM二次开发专题模块培训报名开始啦

    我知道了