PLM之家精品课程培训

PLM之家精品课程培训

联系电话:18301858168   |   QQ咨询:939801026
NX二次开发培训

NX二次开发培训

UFUN/NXOpen C++和实战案例

适合初级入门或想深入了解二次开发的工程师,本培训结合ufun,NXOpen C++,大量的实例及官方内部的开发技术。
公众号二维码

关注公众号

点击扫描二维码免费在线高清教程

课程详情
Catia二次开发培训

Catia二次开发培训

市场需求大,掌握核心技术前景广阔

Catia二次开发的市场需求大,人才稀缺。掌握开发技能潜力巨大,随着经验积累将在汽车、航空等领域有所作为。
B站二维码

在线原创B站视频

点击关注工业软件传道士主页

课程详情
Teamcenter培训

Teamcenter培训

全方位培训,从基础应用到高级开发全覆盖

涵盖用户应用基础培训、管理员基础培训、管理员高级培训及二次开发培训等全方位内容,由多年经验讲师打造。
QQ群二维码

加入同行交流

点击扫描二维码加入QQ群

课程详情
×

PLM之家plmhome公众号

课程涵盖: PLM之家所有原创视频

×

关注B站视频

所有高清视频一览无余,全部在线播放学习

×

加入PLM之家QQ群

同行交流,疑问解答,更多互助

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

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

  [复制链接]

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

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

admin 楼主

2015-2-9 13:45:19

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

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

x

, }1 a" d* U# ^" @NX二次开发源码分享:动态画圆,指定屏幕点和向量相关用法
( d* T1 B& S" h+ k" }7 n$ Q" H; u3 S6 g( A% ^" G  [  z5 d/ i6 E) i
+ x/ D; l- g' |5 {
这个案例很不错的,分享下,程序运行的结果是指定屏幕,拖拉即可动态绘制圆圈!
8 M& U6 c; I9 [9 ^5 ^
& s% G" k9 y: B! m#include <stdio.h>. \: P" V1 s% ?/ n
#include <uf_defs.h>6 x' V6 o0 {. t& e' z  z
#include <uf.h>
% I- q8 x5 A3 `) |( v0 L/ ^#include <uf_ui.h>
: g$ q* |& }6 w5 U* C) y#include <uf_csys.h>  e  I" \0 [- o  k0 W
#include <uf_vec.h>( A' G2 V3 A& V( v1 H- D7 w
#include <uf_disp.h>
% g9 a! O3 q) k0 H1 H3 E4 \, f#include <uf_curve.h>
% s$ g3 u/ R! P* _#include <uf_mtx.h>
5 x8 s5 W% {7 C* i* f1 O#include <uf_obj.h>8 e6 n4 Y/ Z3 S8 N2 I2 W# a
typedef struct3 Y+ f# j; A; r8 N+ p6 a
        { UF_CURVE_arc_t  *arc;1 b5 \5 y  y  S7 [
          double          abs_ctr[3];
5 Z. E: Z6 Y; V) h          double          matrix[9];
3 }) `- H" Y9 t          double          x_axis[3];. B; o( e: a6 c) K
          double          y_axis[3];
# G$ n7 ?$ A8 f# Y6 H0 D        } my_motion_data_t;
7 ?" a, I6 B- e$ i, D/ ]/* Define a motion callback to render a visual representation of+ y6 E( d: g+ y
* the circle to be created, along with a bounding box around the
; x  c+ K  M2 Z; y3 D, `  i * circle, an arc of radius 1.0, and a "rubberband" line from the  v  s% X# c0 Q
* center to the cursor position.' A' F2 W, a5 ?
*/8 H6 z0 M7 n3 h" a
static void motion_cb( double                   *screen_pos,
( ]1 K# o( t9 |                       UF_UI_motion_cb_data_p_t  motion_cb_data,( N# C$ l2 k+ w3 S) W: p" K( x
                       my_motion_data_t        *my_data )! d2 N& \5 T9 K% y9 E% |
{
0 T- l! U  z: T+ Y, W    double radius, pos_array[5][3];
- ]- `! o( }! `' [    double xrad[3], yrad[3], x_y_vec[3], x_ny_vec[3];/ ]* U1 h" ~; b
    /* Calculate the arc radius:  the distance from the arc center% v3 Z3 F. m* ^0 G- j
     * to the current screen position.7 l0 G6 y" b3 N* ?7 Y" @7 X! U
     */
! H1 _& i: d4 x0 @% e. x- o    UF_VEC3_distance( my_data->abs_ctr, screen_pos, &radius );  k, z2 \* N, B% b% ]& {
    /* Map the arc center to the "csys of the arc".
9 M2 e* e9 l4 h1 Y     */
4 g' U2 S2 M* L# X* Q! E6 M    UF_MTX3_vec_multiply( my_data->abs_ctr,
7 N. n" V5 A; U7 i" D  E                       my_data->matrix,4 N% g5 V. @9 U  e) n5 j
                       my_data->arc->arc_center );5 Y: X/ t' m* c6 Z; i
    /* Draw a circle and an arc in the view of the cursor.9 Q1 M% f# P2 {2 V5 C
     */5 Q  O  Y" V7 q! C5 p: ~
    UF_DISP_display_ogp_circle( motion_cb_data->view_tag,' Y; ~! R; O( k
                            my_data->matrix,) i6 U+ X! M1 b: `: K
                            my_data->arc->arc_center,! Q& o, G+ n% h6 V9 g
                            radius );
, h; n: D( e% n6 [- r! M" h    UF_DISP_display_ogp_arc(    motion_cb_data->view_tag,
9 M$ ~7 u( |6 r) B& ^  ]                             my_data->matrix,; `+ Y* t7 Z7 _* m
                             15.0*DEGRA, 345.0*DEGRA,
3 F3 _. w7 j9 j1 D2 i2 U+ y                             my_data->arc->arc_center,
' a, C- [# k2 K! d3 V                             1.0 );6 w  m8 i" l6 l, L7 w2 U
    /* Draw a bounding box around the circle.5 V9 d, X5 t! ^/ O6 Y
     */6 K# _. D- c9 b' W! y& z4 V- ?
    UF_VEC3_scale( radius, my_data->x_axis, xrad );
! C8 i: T& M* J4 _1 Q  Q    UF_VEC3_scale( radius, my_data->y_axis, yrad );$ R8 [  D# G" c+ x1 r' K9 W1 e$ D+ A
    UF_VEC3_add( xrad, yrad, x_y_vec  );
7 s) Z' z* k" e) @! H: H    UF_VEC3_sub( xrad, yrad, x_ny_vec );* d8 L2 r/ m3 a2 E
    UF_VEC3_add( my_data->abs_ctr, x_y_vec,  pos_array[0] );
# c; E# a& E' w, }    UF_VEC3_sub( my_data->abs_ctr, x_ny_vec, pos_array[1] );
* h. R4 k% u5 z/ D' D* d$ ?/ `9 M" n; ~    UF_VEC3_sub( my_data->abs_ctr, x_y_vec,  pos_array[2] );; y! i, B/ T: e
    UF_VEC3_add( my_data->abs_ctr, x_ny_vec, pos_array[3] );
" Z4 [; ]2 P& ?/ l' L- V+ X    UF_VEC3_add( my_data->abs_ctr, x_y_vec,  pos_array[4] );
" ?  ^/ a2 ~6 ~) H. a5 H    UF_DISP_display_ogp_polyline( motion_cb_data->view_tag,
  @- J$ m, s: v  D                              pos_array, 5 );3 E. m1 W2 w. T0 T, f
    /* Draw a "rubberband" line from the circle center to the/ o) ]- h# e7 t
     * cursor position.
$ Y$ o& |: ^0 ]( f1 D7 d     */0 u, O5 F( ~% |* H
    UF_DISP_display_ogp_line( motion_cb_data->view_tag,
) Q+ R$ Y8 [9 b) g) k( i! [0 P# S                          my_data->abs_ctr,$ I5 E# e7 H2 J8 ?. C  e
                          screen_pos );, x# i3 ^2 r# r1 U
}7 P' R; X$ A' N! c: d1 S
#define UF_CALL(X) (report( __FILE__, __LINE__, #X, (X)))
% \' b1 R1 J% _  T$ [, m+ U* o+ F- Hstatic int report( char *file, int line, char *call, int irc)( X& e/ y4 R! J( d: g5 R( p
{2 R& G- W9 T& V: D7 p8 M. e7 u
  if (irc)
- `* f) A% S4 @" G  {: z- c3 M* p5 m) u4 E
     char    messg[133];4 r, ?5 _' n$ @" @; e
     printf("%s, line %d:  %s\n", file, line, call);
1 t1 r6 ?$ H+ H/ o+ R- a     (UF_get_fail_message(irc, messg)) ?  N- @5 b3 Y& m4 w  P" \. w  ]
       printf("    returned a %d\n", irc) :
, @. ^, c4 ^! Q( F       printf("    returned error %d:  %s\n", irc, messg);
  D0 _, U% H* o5 i/ Z9 G: [  }+ _0 A; z+ r6 j1 J% p$ J, s" Z
  return(irc);/ g+ b; a7 I9 O# }- _
}! c+ _9 g; k. u1 A5 _, O+ I
static void do_UGopen_api(void)
5 y8 F4 E5 n0 C{- k5 w2 T2 s5 P0 b  H# p7 _
    int               default_plane;
  _! ?  ]1 {$ R. e4 g0 m    int               plane_resp, ctr_resp, pos_resp;) H( ]: D7 ]( Z& m  v
    tag_t             plane_tag, saved_wcs, mtx_id, csys_id,  K( l: b7 O( E8 |
                      arc_id, view_tag;
! u# ]+ k% i7 |, j0 O    double            plane_matrix[9], plane_origin[3],
7 _: _: w2 ~. r: G# ]# I                      x_vec[3], y_vec[3], arc_edge_pos[3];; y# [' E' q' j$ {" c6 |, w* L! w
    double           root_origin[3] = {0.0, 0.0, 0.0};/ x- A( q+ g1 ~; ]# u$ [2 B# }0 Z
    double           work_origin[3];+ g' o1 \' [% ~" I+ @. l8 P/ _+ T
    UF_CURVE_arc_t    arc;( K/ @  W# p5 i6 ^/ y( s$ ]! p
    my_motion_data_t  my_data;
% W9 A4 }4 W7 M4 L* K4 ?& e; x7 P- L. \, S+ c
    my_data.arc    = &arc;
# I5 y, B. I: a, C    arc.start_angle =   0.0;
, m' m/ R8 X: a8 Q    arc.end_angle   = TWOPI;    /* Create a full circle. */
- c& C1 |1 o+ |) _3 `    default_plane   = 5;       /* Default plane = WCS */
6 @; t6 V- z. T  z& J    do7 u& E5 n8 J0 p2 Z9 @- t
    {  U. K* D, I6 T
        /* Specify the plane on which the circle is to be created.% T9 Q" I1 ]% s0 f0 p4 M
         */( P. P- H& \# R# f
        UF_CALL(UF_UI_specify_plane(! W' w7 g5 N! C: _$ q
                         "Specify plane for circle creation",
8 x2 R4 o+ j4 A( X7 U                         &default_plane,
0 d% i# H( a! k- w. P& o2 F, d' c                         1,
# M" b# D, y( a7 E8 V% `                         &plane_resp,
+ |4 O: a* o/ ?3 M- C) c2 {) M                         plane_matrix,; l. S! V1 O  v6 s
                         plane_origin,
2 M3 }3 m& Q  X, q# H5 |. M$ Z* V                         &plane_tag ));: p3 X% p' N( u5 m' A8 d
        if (plane_resp ==3)5 L! t& K6 m: `4 z+ d% E
        {' w( a' ]/ L2 H! M9 ]8 ?
            /* Save the current WCS for future restoration.# X2 h7 I3 J  S" H
             */
. w6 g& C( X) g. \1 O: ?9 ~  D2 s! T            UF_CSYS_ask_wcs( &saved_wcs );& g, U4 p8 L3 [& u  h
            /* Move the WCS to the specified plane. This is2 O4 B8 R; K! X. s% x1 Q% S
             * necessary because the position passed to the motion8 ]' c. Y9 u0 F  g
             * callback, and the position returned by4 Q1 T/ h$ l0 d# p, q. t
             * UF_UI_specify_screen_position, is the screen6 V/ m1 [* F6 [
             * position projected onto the WCS XY plane.( I) _' z' F7 b/ G
             */
- C2 C/ q: P  e! O2 g3 U. ?            if (default_plane != 5)
' W  t" Q1 f( C; X, g2 g            {
+ A) N8 l' n5 t) x1 n7 ]                UF_CSYS_create_matrix( plane_matrix, &mtx_id );( [0 H- ^& ~5 v  R. @
                UF_CSYS_create_csys(  plane_origin, mtx_id,
* J8 g" j' V, f# Q% X9 c8 w0 {                                   &csys_id );- Z- ~7 q4 N7 \6 ^8 B, z, c
                UF_CSYS_set_wcs( csys_id );
+ {/ y: p/ P! W. A            }; [* G% J+ R% M0 g
            /* Obtain unit vectors and the arc matrix relative to( f$ D9 h- d2 ]: R
             * the Work Part coordinate system.
* ^2 R2 E) Y* T2 R             */; t, O" D8 T- y. x- G
            UF_MTX3_x_vec( plane_matrix, x_vec );
5 n1 }$ c7 N6 g7 _            UF_MTX3_y_vec( plane_matrix, y_vec );' R' \: R! T9 z% c# s' C
            UF_CSYS_map_point( UF_CSYS_ROOT_COORDS, x_vec,
  U4 l- h0 O& F1 I! c                            UF_CSYS_WORK_COORDS, x_vec );
$ _* f4 Z3 k6 z$ ]            UF_CSYS_map_point( UF_CSYS_ROOT_COORDS, y_vec," S8 N: T2 x' g0 f( {
                            UF_CSYS_WORK_COORDS, y_vec );% K" I+ V# {; [% K( P+ n
            UF_CSYS_map_point( UF_CSYS_ROOT_COORDS, root_origin,- V' N2 L) L0 i  h2 {  g" k
                            UF_CSYS_WORK_COORDS, work_origin );
( `6 p. F% y/ e8 m0 T            UF_VEC3_sub( x_vec, work_origin, my_data.x_axis );
. z6 n# i' {7 j# {7 y) r/ |2 ~            UF_VEC3_sub( y_vec, work_origin, my_data.y_axis );
8 ]" _/ Y& q+ M0 U' l            UF_MTX3_initialize( my_data.x_axis, my_data.y_axis,) f5 E  s* ~$ c7 f4 d4 }- }
                             my_data.matrix );- F% {5 t. N7 t+ q8 h  ^8 ]
            UF_CSYS_create_matrix( my_data.matrix,' z! k: n2 s% S2 z6 o* E
                                &arc.matrix_tag );' D7 |, R3 S5 f& L
            do
& D: g( \+ G9 I4 ?9 j$ X) ?, Z            {+ m: [% L/ b# y+ R+ r
                UF_CALL(UF_UI_specify_screen_position(
% I# N( g& i( V7 E                                "Specify arc center",3 z, @) d  e' {- o& U2 c4 R- D
                                NULL,
2 x/ `) j2 w0 D, U- m                                NULL,1 q2 I3 _- J; k* R1 i7 b! i
                                my_data.abs_ctr,5 Q1 t+ h- M9 t3 O7 F$ W. b2 Y& ^
                                &view_tag,
9 `2 r* w! y1 l5 U- x! I2 }! A                                &ctr_resp ));
9 ]0 a# F; N! ~2 ^9 Q% [" R                if (ctr_resp == UF_UI_PICK_RESPONSE)0 O8 d, g, P  n& C% F
                {6 Z: `" J6 ~, T9 s  O
                    /* Map the arc center to the arc csys.
+ |3 V8 K6 r6 N4 ?( k# T' x+ D6 L                     */2 \" _3 \8 v9 j4 a3 U( M4 d
                    UF_MTX3_vec_multiply( my_data.abs_ctr,, r% Q! P" w: N6 z/ i7 k
                                          my_data.matrix,
+ e: e! B4 V0 T, G% m( G7 H/ v                                          arc.arc_center );
9 Y1 L5 }- Z# l+ V8 e0 A* i                    UF_CALL(UF_UI_specify_screen_position(  n$ ~# V* w* V' f+ ]% Q
                                    "Indicate arc radius",& r. ?5 Z7 l. X7 F5 b7 k" R
                                    (UF_UI_motion_fn_t)motion_cb," C0 J) |. C- y; `3 ?3 c
                                    (void *)&my_data,& X) w4 d6 [/ `3 ^9 o) l- U4 P
                                    arc_edge_pos," [; ~7 d' z  {& |
                                    &view_tag,( i4 r6 `) h$ N7 t  p$ |4 |; K# n
                                    &pos_resp ));8 M( l# ]4 Q- H+ A9 m
                    /* If a position was obtained, create the
+ s; v# D8 P3 g5 N# M                     * circle.
' [- G& k. ]& B                     */  `2 Q" K1 J. G( a3 h
                    if (pos_resp == UF_UI_PICK_RESPONSE)
0 W8 E' d1 k! u# z3 ?! c                    {/ e' U  Q8 T' ?! u% z& V. `& e4 _8 K# B
                        UF_VEC3_distance( my_data.abs_ctr,
' ~; L; j) Y0 M4 w0 c/ y8 m+ ]                                        arc_edge_pos,
8 M# X8 |0 ?8 G# i2 W                                        &arc.radius );) j/ X, `( i( b* u! Z
                        UF_CURVE_create_arc( &arc, &arc_id );+ y  P5 G& H1 }3 B. B
                    }: d: g1 \! }1 Q2 O0 I
                }* _, j+ `2 B7 G  O. }+ T! s
            } while ( (ctr_resp == UF_UI_PICK_RESPONSE) &&$ @( E/ P5 h$ h& {1 w
                     (pos_resp != UF_UI_CANCEL)           );
# W* d4 D/ Z  m* \! J3 _8 U            /* Restore the WCS if it was altered above.
" X4 P+ J- n. A$ n             */
5 d# D. B/ w2 T3 _3 u2 S$ W: u6 B            if (default_plane != 5)7 m7 S# g! p) G  C% v3 Y
            {: r0 y2 w0 I0 W+ L  Z( u
                UF_CSYS_set_wcs( saved_wcs );
( i; |' a8 n8 H* d9 B                UF_OBJ_delete_object( csys_id );
2 |& v2 R1 m& s2 f8 }            }6 P% s; X- x  e6 n0 H( K5 k: u
        }! S( `* @7 j$ {  s9 e
    } while (ctr_resp == UF_UI_BACK && plane_resp == 3);
; u6 ~" R! V+ q4 g1 q/ b& _% M}
0 H3 h. k% k7 v$ s& M5 b) R# Y/*ARGSUSED*/
: _+ @6 S& S8 ~. ]( hvoid ufusr(char *param, int *reTCode, int param_len)( z9 u% {4 F  h! v( n4 d3 }) H
{
8 h4 E* Z# y; g" `, E  if (!UF_CALL(UF_initialize()))
, n% a9 Z  v4 I  e9 L' Y  {
; ?! ~: H, f% L6 X& `3 j$ D) T    do_ugopen_api();# M# W3 q0 h: q: |5 o2 P5 t" d
    UF_CALL(UF_terminate());
1 q) u/ E& E3 N; D  }
, R4 }9 d; ~  l}- G; R8 k% g8 P( {2 S/ p4 c
int ufusr_ask_unload(void)
1 A+ x; ^  X! N; M7 @/ @' c# y, s{
! a6 _# `$ a. \) Q* y3 N# c  return (UF_UNLOAD_IMMEDIATELY);9 Z. @0 k! ~+ m  ]: x, F: |
}
0 S" x7 l: b! {! \$ J" l* @1 W! Z! I  Q% _0 w: Z
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了