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 6309 2

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

admin 楼主

2015-2-9 13:45:19

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

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

x
- k) w1 D/ t" M* s
NX二次开发源码分享:动态画圆,指定屏幕点和向量相关用法
3 ]( {9 [+ s& Y: I) |6 c4 n' J) M% I0 Y8 U
" f& F$ n; d6 S3 P
这个案例很不错的,分享下,程序运行的结果是指定屏幕,拖拉即可动态绘制圆圈!# q+ P( N' X& v3 I' x4 L  _

0 i, i, p' B2 u7 O: k5 m#include <stdio.h>* r7 q; W. p% D- `& P9 A
#include <uf_defs.h>
8 Z# f7 t" D& a# }- {#include <uf.h>) l4 Y/ i( \+ d% V
#include <uf_ui.h>+ s8 R3 ?" f; c- o  i
#include <uf_csys.h>1 c0 s6 a% f+ h
#include <uf_vec.h>
' Z" o  z& P# M: d+ Z' H+ Z6 K#include <uf_disp.h>
# U, K$ ?* w  x3 c2 n#include <uf_curve.h>
. k, A& X5 f% x3 _- x#include <uf_mtx.h>/ O; z; a5 j$ i
#include <uf_obj.h>6 k9 z$ g" G0 d" t0 a
typedef struct
& N: }" Y( l) x' A        { UF_CURVE_arc_t  *arc;2 A. y5 g$ n% p0 ]2 h' H, O
          double          abs_ctr[3];
+ X+ p, B8 s: L# D          double          matrix[9];0 M% g, v& ]9 N, ]1 b
          double          x_axis[3];8 S, ]2 s2 ?* {' }  p8 n3 `
          double          y_axis[3];; i- e; D7 ?( g% K2 U: @
        } my_motion_data_t;  u' u! }0 U$ A
/* Define a motion callback to render a visual representation of5 @1 K. T1 [3 V# t) k
* the circle to be created, along with a bounding box around the; y+ u. J0 W; z5 ^9 m' l
* circle, an arc of radius 1.0, and a "rubberband" line from the
" g( m" o0 S2 e' `1 T * center to the cursor position.7 u, l& D* }3 r3 F
*/
7 \" S- W& B: T! Y" v/ @1 Astatic void motion_cb( double                   *screen_pos,
. U1 B: E7 I. n  `2 w                       UF_UI_motion_cb_data_p_t  motion_cb_data,7 V4 U9 t+ f; Z/ ]  h
                       my_motion_data_t        *my_data ). r- x% T& s" P9 B0 x( c
{# l8 {8 C: h$ y  J
    double radius, pos_array[5][3];7 F! X* t0 B( D2 T& L  q
    double xrad[3], yrad[3], x_y_vec[3], x_ny_vec[3];; L; t* K; z9 O4 I% D: }; e
    /* Calculate the arc radius:  the distance from the arc center' q" r% Z0 [2 B! m0 I# s
     * to the current screen position.
' |4 ^1 m' H1 F+ O     */: p  S' u6 f: B* m
    UF_VEC3_distance( my_data->abs_ctr, screen_pos, &radius );7 ]" Z1 n) C* ?  H7 p: y
    /* Map the arc center to the "csys of the arc".
+ w6 g- S+ t$ J, V2 n, h, P/ @     */
% H# M3 E+ X/ V  w* c/ g    UF_MTX3_vec_multiply( my_data->abs_ctr,: Z; ~" z. S+ [4 A& K
                       my_data->matrix,
4 U. U; [8 O; U$ F2 X& [                       my_data->arc->arc_center );
3 `: `' D) z5 _4 {) c0 z6 e    /* Draw a circle and an arc in the view of the cursor.
/ n# q9 I  ?9 O0 _1 T/ d     */* z5 V: S- y1 w
    UF_DISP_display_ogp_circle( motion_cb_data->view_tag,
* N; d) W7 x8 L6 K( }+ m% y                            my_data->matrix,. Y" C! d# b$ |
                            my_data->arc->arc_center,8 G7 @/ R* i0 L9 ~& S" K
                            radius );6 c" r5 J: |/ G  D# \: j
    UF_DISP_display_ogp_arc(    motion_cb_data->view_tag,
- ]; I7 V+ M- w) A: z                             my_data->matrix,
. Z) w( c% U/ s% U4 t# X) g6 l0 \* z' k                             15.0*DEGRA, 345.0*DEGRA,- j  V3 f. t# I% _
                             my_data->arc->arc_center,2 Y4 l- {/ B# i7 Y( j" [. \: i
                             1.0 );; ~7 ?6 u; v+ m+ V
    /* Draw a bounding box around the circle.
2 K4 s# p: v; ^     */
/ ?" T! A1 W9 X! `" C' B    UF_VEC3_scale( radius, my_data->x_axis, xrad );
$ E! `% I- R  N. X+ v    UF_VEC3_scale( radius, my_data->y_axis, yrad );( J; b$ p9 `# Y+ Q- Y7 I$ R! X+ D9 `
    UF_VEC3_add( xrad, yrad, x_y_vec  );- y' g8 C/ I. Z
    UF_VEC3_sub( xrad, yrad, x_ny_vec );
- o( G- _! x' u3 ?    UF_VEC3_add( my_data->abs_ctr, x_y_vec,  pos_array[0] );9 K2 ]* t7 C( R# }! t
    UF_VEC3_sub( my_data->abs_ctr, x_ny_vec, pos_array[1] );" S/ ]; c$ x2 J2 B/ o- e/ B
    UF_VEC3_sub( my_data->abs_ctr, x_y_vec,  pos_array[2] );
6 w& I' c/ Q9 a0 N) a$ g    UF_VEC3_add( my_data->abs_ctr, x_ny_vec, pos_array[3] );8 Y4 Q$ _" Q  D, R4 r/ y3 Y5 G
    UF_VEC3_add( my_data->abs_ctr, x_y_vec,  pos_array[4] );
8 p- y$ h0 E2 @5 ]3 ]    UF_DISP_display_ogp_polyline( motion_cb_data->view_tag,; E% t0 E3 y4 r  x2 K8 {
                              pos_array, 5 );: J8 {# Q1 R- c% C3 H8 l* m  p9 O
    /* Draw a "rubberband" line from the circle center to the
* Y# C& P& W/ j7 T% P* o     * cursor position." a% E& h2 ^$ w7 {9 f8 f1 F* P
     */: ?9 h- ~2 j5 t# Z( A
    UF_DISP_display_ogp_line( motion_cb_data->view_tag,
  G; ?7 F0 s  @0 p                          my_data->abs_ctr,
" o4 z" a1 O* j, R, L, G' V                          screen_pos );  J; R* B4 V0 i! I
}5 s  A, E1 F' u) j5 R
#define UF_CALL(X) (report( __FILE__, __LINE__, #X, (X)))
0 Y% p5 n% q2 r: z. T9 t+ {static int report( char *file, int line, char *call, int irc)
  W* ?( r" ]; B{, L4 o/ D6 |1 d
  if (irc)
) ?* Q! `! S9 L) b+ o; O) s1 |  {
( a" S3 I8 u3 I% m2 n! e, D     char    messg[133];
8 R, q+ I* i$ n0 o3 A  T     printf("%s, line %d:  %s\n", file, line, call);0 B: p( [5 x" L( H7 Q9 J0 H, V
     (UF_get_fail_message(irc, messg)) ?! T- w: g9 c( `( `2 y! i; O* k4 p
       printf("    returned a %d\n", irc) :
" F7 T5 T  G7 C4 L. ~       printf("    returned error %d:  %s\n", irc, messg);
6 i, P1 l+ p- j" y: d  }
- a# z6 j+ A$ j2 P- m  return(irc);7 D- @7 {+ c6 e8 ^/ P, U
}
# ~. C5 R4 q4 L! C9 D, ?static void do_UGopen_api(void), q% `4 Y/ D; B# p4 F! L
{
4 {* W4 O5 h. x3 x    int               default_plane;
% q/ Q" X1 Z& r! D; K1 d6 j    int               plane_resp, ctr_resp, pos_resp;& i+ c) |" B3 O0 z* l! q( a' R% I5 @
    tag_t             plane_tag, saved_wcs, mtx_id, csys_id,  L( a! d0 N5 b8 N
                      arc_id, view_tag;
9 f3 e( `$ W: Q  |$ |" A    double            plane_matrix[9], plane_origin[3],
5 X; q5 f: [! N: {& |2 \/ d5 e; t                      x_vec[3], y_vec[3], arc_edge_pos[3];3 w, J% @6 [0 n! I; v
    double           root_origin[3] = {0.0, 0.0, 0.0};$ G! g8 \: V: o9 k) k; E5 S- M
    double           work_origin[3];1 p4 U" C) ^5 S( _/ a# ^
    UF_CURVE_arc_t    arc;8 t, o3 l- W! Z5 f
    my_motion_data_t  my_data;8 y" H  ~. V2 |9 Z# I) M0 t- P

) A4 n5 i# n6 v# p8 p    my_data.arc    = &arc;6 Y' i$ Q* f. j& n. n9 S% ^. h5 ], [8 a
    arc.start_angle =   0.0;  i) {6 e$ {' {/ Y
    arc.end_angle   = TWOPI;    /* Create a full circle. */
$ A/ ^% v7 D7 G2 O( Z6 c    default_plane   = 5;       /* Default plane = WCS */
8 \) o' Z& V8 T8 v! Q    do
; o1 Z) u/ g, A% L- `8 L    {
3 ^2 A* E, p, o3 ]1 }. q' |        /* Specify the plane on which the circle is to be created.
1 D* x0 \) ]  k         */
! V1 B/ o5 R  o2 u5 b: H' a        UF_CALL(UF_UI_specify_plane(
/ C2 C: \2 q* X, [                         "Specify plane for circle creation",
' Y. ?8 x( _2 C: J6 ]                         &default_plane,
4 h: b3 q' _1 g4 [9 H9 k' y- t                         1,
) I% |$ M" B9 C+ L6 a                         &plane_resp,1 B/ h/ W- P/ Z9 e; t0 Z
                         plane_matrix,3 R' h/ }  n# G+ U0 E: F# X
                         plane_origin,
4 f( `; \  V' N0 o. O6 I# F                         &plane_tag ));6 s3 D! K* ~! M1 P( x$ r& k
        if (plane_resp ==3)
7 r/ n! s% A- r        {+ A- [5 W& z8 U' V7 Y
            /* Save the current WCS for future restoration.
  k6 W8 x. D! g- U             */
8 a8 k- e1 C9 `# x: A9 o& A# H            UF_CSYS_ask_wcs( &saved_wcs );& w) d2 U3 c2 f3 O. F4 E
            /* Move the WCS to the specified plane. This is! Z: Y# K% x1 n% }9 ?5 }- Z
             * necessary because the position passed to the motion6 M3 x/ J. u" f3 x) g6 F; J0 N
             * callback, and the position returned by
, j4 @& S$ R. n: V: @& l             * UF_UI_specify_screen_position, is the screen
6 O, j5 ?; X: B  ], X7 s6 ^; U             * position projected onto the WCS XY plane.5 s& `0 p" u9 I9 Q/ D3 j
             */
% X& Q- k0 c8 k+ a3 K9 }+ R            if (default_plane != 5): [+ i( J- R0 k4 k
            {
' E. n/ l2 \1 V  j; c5 x+ N                UF_CSYS_create_matrix( plane_matrix, &mtx_id );
% k& d: d% X& P& l" e* ]$ _. F: m. r                UF_CSYS_create_csys(  plane_origin, mtx_id,
/ _1 q! s5 l5 }8 D& [/ b" x5 D                                   &csys_id );
# N: I) W, f+ d, W( S3 ]0 M                UF_CSYS_set_wcs( csys_id );
& x( k+ t7 u5 Z0 v: ~9 Y0 l            }
  E" i$ C7 L5 R, Y0 ^( n' M            /* Obtain unit vectors and the arc matrix relative to
+ z# _/ l# e) Z& t             * the Work Part coordinate system.
" E8 E8 h# i! g0 `6 g             */- ?# v9 C. W9 t7 |* g
            UF_MTX3_x_vec( plane_matrix, x_vec );7 s% r$ A4 W, _+ h! _+ z
            UF_MTX3_y_vec( plane_matrix, y_vec );4 d: {# d, i- ]/ C
            UF_CSYS_map_point( UF_CSYS_ROOT_COORDS, x_vec,) \7 B6 ]$ P1 u: f
                            UF_CSYS_WORK_COORDS, x_vec );
7 v; x8 }3 ?9 V0 J3 m* c9 j            UF_CSYS_map_point( UF_CSYS_ROOT_COORDS, y_vec,8 N$ Y* ?3 d& Q' G7 {
                            UF_CSYS_WORK_COORDS, y_vec );/ @( ~" t. P+ t% f
            UF_CSYS_map_point( UF_CSYS_ROOT_COORDS, root_origin,8 X- N, M. j# v3 T
                            UF_CSYS_WORK_COORDS, work_origin );
% W" _2 O; C6 U. v3 R+ [7 X5 D            UF_VEC3_sub( x_vec, work_origin, my_data.x_axis );, [/ o" m4 D5 _: T' J  q% y
            UF_VEC3_sub( y_vec, work_origin, my_data.y_axis );9 {7 E: \6 i' u3 s3 Z, W
            UF_MTX3_initialize( my_data.x_axis, my_data.y_axis,, w1 x. p- V! _: b$ L5 o
                             my_data.matrix );4 Z4 @& ~/ s9 ~) S
            UF_CSYS_create_matrix( my_data.matrix,/ @7 M( g4 G/ X: ]
                                &arc.matrix_tag );+ t7 a; f8 R1 }7 y  K+ W
            do# G3 R: B2 d. H+ ~+ ~7 r
            {2 P: o' n7 ?9 }2 G6 R
                UF_CALL(UF_UI_specify_screen_position(( i$ L: `1 Y3 v. F8 j7 D' B
                                "Specify arc center",
( C2 y9 h1 {' J1 t4 [                                NULL,
/ o$ M. A0 \8 s6 U& X                                NULL,$ E4 I: S1 `; [! x
                                my_data.abs_ctr,
7 x8 y5 i0 {+ }7 V& r7 I                                &view_tag,
9 _: V  y2 v5 f6 B3 ^( @                                &ctr_resp ));. V7 j9 _9 }# e- P  [5 V7 }2 S0 _
                if (ctr_resp == UF_UI_PICK_RESPONSE)9 @7 M6 P+ c' L2 b' {3 l
                {/ O5 s, u3 {5 E0 P" E
                    /* Map the arc center to the arc csys.
3 F, o% B5 q- ~% N: T6 H) H                     */6 o5 m5 g2 G. Y) g
                    UF_MTX3_vec_multiply( my_data.abs_ctr,
" D6 l- d7 j; Q3 ^9 O                                          my_data.matrix,* P: ~. z5 T2 R8 k. \3 v* g
                                          arc.arc_center );
4 d3 U; D; h: P) W: F" I                    UF_CALL(UF_UI_specify_screen_position(" v2 h% n4 ^4 |. `5 U, M
                                    "Indicate arc radius"," _% G; S+ v4 l; a6 a8 b7 }
                                    (UF_UI_motion_fn_t)motion_cb,2 ]" W" ~+ j2 G. M3 T& [3 B, c
                                    (void *)&my_data,
) C& Y% L7 Z+ F6 w                                    arc_edge_pos,
9 N3 y9 ]7 f: K2 p                                    &view_tag,
3 b9 b: C% p' J" l                                    &pos_resp ));
7 p6 G$ P: |4 w/ X                    /* If a position was obtained, create the" J  J/ w3 d) v: y. O  N
                     * circle.% E2 Y1 I! U* P/ P3 r
                     */7 C6 ]  E2 N3 P) L- t
                    if (pos_resp == UF_UI_PICK_RESPONSE)
9 d4 Q7 |, X$ g% y7 e: x1 Y( r- G6 H                    {
/ U% b9 [# {- I) W) {" u                        UF_VEC3_distance( my_data.abs_ctr,
6 V9 T% x5 G9 w                                        arc_edge_pos,- X1 e$ h& E( n8 S8 K! @
                                        &arc.radius );0 p% I. A' @; H7 |
                        UF_CURVE_create_arc( &arc, &arc_id );
9 j7 L& R% L* s6 q, ~4 F( Y2 {                    }
" L: c; Q9 |7 u* E6 m                }# ?9 q8 p5 `: V1 C4 O
            } while ( (ctr_resp == UF_UI_PICK_RESPONSE) &&# q% l: l3 ]# ~# O) ]* x, `' J
                     (pos_resp != UF_UI_CANCEL)           );- {+ `) S7 N, e2 O
            /* Restore the WCS if it was altered above.
6 h/ _7 f4 z  ~' c; Y             */
* t1 p* r( B. u, l9 t/ s' N" v            if (default_plane != 5)
  B! ^" D6 G: ?" W! |" k+ R            {
% N4 g, E" X' O# @! t                UF_CSYS_set_wcs( saved_wcs );$ V' H% i9 ?& m3 w
                UF_OBJ_delete_object( csys_id );/ i( P6 a; I  L1 z
            }4 ^4 c  w6 t% l" f2 ~4 d+ S" |% W- u
        }; P! _5 L: h8 C4 p/ ?8 t
    } while (ctr_resp == UF_UI_BACK && plane_resp == 3);
; T* y+ X0 T$ [7 G* I+ y}+ o6 c# O, n# s5 L% E7 z
/*ARGSUSED*/
3 ~0 r/ Q- c3 @8 {% D6 cvoid ufusr(char *param, int *reTCode, int param_len). }+ ?$ g. v9 W! ~9 Z) z
{
) A2 k+ J. U) l' {  f; ?( @  if (!UF_CALL(UF_initialize()))5 K) v, @/ j6 X2 P, m
  {5 \; z3 b3 b$ y
    do_ugopen_api();
8 h1 L. i6 A- n6 H" i    UF_CALL(UF_terminate());. L6 K8 e8 {4 t* R9 Z
  }
5 P0 o5 f/ n' ?}
% C" s5 x6 h4 r4 aint ufusr_ask_unload(void)$ @. `2 l" n' u# u6 J
{
) S; Z1 D, E. u* Q9 N: s# {) B8 k  return (UF_UNLOAD_IMMEDIATELY);
- ~! S% y! r5 Q}; G* h- j. g0 I

2 d8 h$ V3 }" j6 k5 U8 |# Z/ `" N' [
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了