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

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

admin 楼主

2015-2-9 13:45:19

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

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

x

4 t& O' I+ w" R5 ]0 t5 w# [$ R" bNX二次开发源码分享:动态画圆,指定屏幕点和向量相关用法( A7 X  I. N" ^' r5 w
8 U0 K5 L" E( {, f1 T8 h  x: u

1 }8 l3 r. }/ U这个案例很不错的,分享下,程序运行的结果是指定屏幕,拖拉即可动态绘制圆圈!
  ^2 U  s0 G& L- V8 A% o
5 u9 K5 r" f' k) i8 S5 H1 N# L#include <stdio.h>
3 F) Y8 p( m* M1 V! o#include <uf_defs.h>
) V8 L; R$ j- n& L#include <uf.h>; e0 r- r: t! ^
#include <uf_ui.h>
; b% k/ D* p/ v' p% r, [. M0 l  `#include <uf_csys.h>
3 c9 A* o9 [: H6 C. ?6 q#include <uf_vec.h># a! y% n; v8 S4 d
#include <uf_disp.h>$ ^1 I( k3 K  q  S% e1 f
#include <uf_curve.h>+ w; }8 I3 h6 s& q1 c6 n- t
#include <uf_mtx.h>( C% D1 j0 J% A- E- b
#include <uf_obj.h>
6 m; M2 K3 i2 M2 P+ B  a! _3 \9 Ktypedef struct. @* T# E# A8 V* j2 J" s
        { UF_CURVE_arc_t  *arc;! Z0 j) w( L0 J7 g; x- Z
          double          abs_ctr[3];
) @- Q- h; t6 Z: N! |+ v8 q          double          matrix[9];0 V- k5 ?6 f" `
          double          x_axis[3];% o, N; B5 I( x0 i+ G6 J2 ^5 n1 K3 E
          double          y_axis[3];% ]0 k* P2 Q' r1 I
        } my_motion_data_t;
* V! t7 [+ W5 B" k( s$ {4 c+ `/* Define a motion callback to render a visual representation of* u) g, ~/ X3 l0 k/ ^" J& T
* the circle to be created, along with a bounding box around the
3 Y, h  e# l- U' h * circle, an arc of radius 1.0, and a "rubberband" line from the8 h) E  a3 {8 a; |
* center to the cursor position.
! t" u" ]% Z2 b4 Q */! v* p1 t# ~5 B+ _/ i) W
static void motion_cb( double                   *screen_pos,
4 j& G& Q' c! }( D; q* x                       UF_UI_motion_cb_data_p_t  motion_cb_data,
  R( ]9 ^2 K+ b' i! x! ?; P/ }  ]                       my_motion_data_t        *my_data )  X/ x% `- s9 m' [
{
" ~* O$ G7 f8 `    double radius, pos_array[5][3];
+ x8 v  h( c) b% s* G    double xrad[3], yrad[3], x_y_vec[3], x_ny_vec[3];1 ^2 y9 v$ X2 s8 [4 l; ?) Z4 u
    /* Calculate the arc radius:  the distance from the arc center3 D' b- W" e6 j  h% A8 {$ \
     * to the current screen position.
4 k. R7 t1 [; A- u% P$ m     */$ d  l8 B% Y0 w( k2 Q2 h' |' Q
    UF_VEC3_distance( my_data->abs_ctr, screen_pos, &radius );
4 |2 h, D/ Q% x# _. G+ g3 x8 U    /* Map the arc center to the "csys of the arc".
. M, d( \) {2 G/ E) r. y$ D     */
* m; N0 F5 x- c    UF_MTX3_vec_multiply( my_data->abs_ctr,  {* G% J4 ?' \
                       my_data->matrix,' D/ T: c& P9 N: l
                       my_data->arc->arc_center );
& q1 H  x7 b8 W6 c( j1 M8 k9 G    /* Draw a circle and an arc in the view of the cursor.. \7 A* y! a7 X) I6 o/ G
     */& Q/ S8 ^- A/ H+ P
    UF_DISP_display_ogp_circle( motion_cb_data->view_tag,
  m5 b1 Y* u5 q* x6 w; {9 h3 s                            my_data->matrix,
7 Q, h7 X$ H- E6 x( h" D3 q1 M                            my_data->arc->arc_center,
7 b" O+ p" c  [                            radius );* \& o! j! S4 ~) X+ @
    UF_DISP_display_ogp_arc(    motion_cb_data->view_tag,
% E4 T+ y) q* a% |& ?                             my_data->matrix," \$ b; d/ g) d& ]; I
                             15.0*DEGRA, 345.0*DEGRA,
- {- S  s; P- G+ u( l                             my_data->arc->arc_center,
7 y& ]7 M9 Z: p3 G' ?% y                             1.0 );
1 {: @! ]4 i( k! x1 w2 c    /* Draw a bounding box around the circle.2 P& Q7 [" @0 @
     */4 ?0 x. }7 a- Y/ D6 t2 h8 f# S
    UF_VEC3_scale( radius, my_data->x_axis, xrad );0 ~% V; S$ L, W9 P% r( x+ Z$ @
    UF_VEC3_scale( radius, my_data->y_axis, yrad );
6 x# g* F# d& _    UF_VEC3_add( xrad, yrad, x_y_vec  );
% [8 H: E% G( Y' @# m/ }) x    UF_VEC3_sub( xrad, yrad, x_ny_vec );8 _, s/ \5 a' h
    UF_VEC3_add( my_data->abs_ctr, x_y_vec,  pos_array[0] );% ^4 p, x8 e# h8 W, a- [( k" Z7 Z
    UF_VEC3_sub( my_data->abs_ctr, x_ny_vec, pos_array[1] );# J! b) X6 x+ K4 I( P8 _
    UF_VEC3_sub( my_data->abs_ctr, x_y_vec,  pos_array[2] );9 U) n0 Y" ^5 m! V
    UF_VEC3_add( my_data->abs_ctr, x_ny_vec, pos_array[3] );1 R1 f  e8 y/ H* Y! i4 Z/ s
    UF_VEC3_add( my_data->abs_ctr, x_y_vec,  pos_array[4] );& N4 C6 p& E" B- k) e* H
    UF_DISP_display_ogp_polyline( motion_cb_data->view_tag,
1 H/ z5 z# E+ n                              pos_array, 5 );
# |9 l5 q# G7 Y* A    /* Draw a "rubberband" line from the circle center to the
9 Q) M0 I/ {. P6 H; W     * cursor position.! V1 B7 i' j6 L" l
     */
0 \; T7 m. d$ f, Y, @    UF_DISP_display_ogp_line( motion_cb_data->view_tag,
; L( R/ F" N6 s. d                          my_data->abs_ctr,4 t& ^9 o+ h" k. z
                          screen_pos );' Y. d3 }! r0 ]& L. h& M: L
}- p9 `9 U4 ?) R* d
#define UF_CALL(X) (report( __FILE__, __LINE__, #X, (X)))
, J9 M& m& u% ?' K; s  ]: tstatic int report( char *file, int line, char *call, int irc)  O5 Y) c/ l6 j2 u* w1 @& n1 [
{
3 |5 c4 H+ d$ n" a2 }5 H  if (irc)7 N9 ], o" c! T
  {2 h' w* s6 u/ [
     char    messg[133];+ X# z5 V0 @+ `# g
     printf("%s, line %d:  %s\n", file, line, call);: f- A& F* A) \4 i; f
     (UF_get_fail_message(irc, messg)) ?* M( E# E/ `3 h
       printf("    returned a %d\n", irc) :
( J% B0 k9 [" M- O2 B       printf("    returned error %d:  %s\n", irc, messg);- o7 h/ \" N# t& g9 c/ R/ S
  }
, N0 S: U1 y( _  return(irc);
$ r" @* H. l# N& ]1 ?9 _3 x' Q}
4 H$ ~* g! N* |static void do_UGopen_api(void)+ w" P2 K0 r* S8 a  Q: |! ~
{
' w2 i* @0 ?& k, ^, `    int               default_plane;
9 y6 U4 ]! l- \    int               plane_resp, ctr_resp, pos_resp;
2 e3 C! ?( n0 f/ s1 }& Z; Z% d    tag_t             plane_tag, saved_wcs, mtx_id, csys_id,7 v: @6 D9 [4 F, E0 m3 m( m' l
                      arc_id, view_tag;$ Z$ ], Y# z# ^  h6 e* l' A" H
    double            plane_matrix[9], plane_origin[3],: }& s5 Q3 `  V' ~5 U, R8 V/ m
                      x_vec[3], y_vec[3], arc_edge_pos[3];
0 M3 S# Y2 H+ u; V$ ]" ]    double           root_origin[3] = {0.0, 0.0, 0.0};
: X  n( g9 T7 _8 I& e    double           work_origin[3];
$ o: ~7 u* I+ k* n$ A    UF_CURVE_arc_t    arc;. ]/ C: P, {! M! L( n3 g& w
    my_motion_data_t  my_data;
8 c+ D& ]# @2 ?. a, ^, }. A
! [, e" p% F9 F" B    my_data.arc    = &arc;) ^, B' D1 \. |
    arc.start_angle =   0.0;
& u5 n) S* G5 Z    arc.end_angle   = TWOPI;    /* Create a full circle. */+ k1 V1 t1 F. I  O0 p
    default_plane   = 5;       /* Default plane = WCS */  l/ H6 U' Y/ |
    do
/ K- [( D- n/ }! |) a+ `    {( S) q5 y! O  D  i  V
        /* Specify the plane on which the circle is to be created.# n! U2 ~3 t( W* {# L, J/ o& Q3 W. T
         */' K) `9 @. y' j9 m9 |8 C3 G! Z
        UF_CALL(UF_UI_specify_plane(& f" ~$ ~; I+ |3 K( a! b
                         "Specify plane for circle creation",3 J+ b$ a* X- w/ h1 u) @
                         &default_plane,
" c& Y8 k8 @+ ^/ S7 B2 O                         1,8 D* B, a% j% u, l; `  r6 p; ?
                         &plane_resp,& y/ I1 i$ J5 k1 B( t
                         plane_matrix,
. K5 f* B5 p( V. i, G                         plane_origin,' F6 L2 ^, B4 }8 v1 Y0 [
                         &plane_tag ));
2 S- V2 }3 |& R0 L        if (plane_resp ==3)
7 U) O- Z! n1 T4 y4 t        {
! x/ f" n9 y% r: ~            /* Save the current WCS for future restoration.8 g! W8 L& b% V0 n
             */
! F8 X8 ]* `3 z            UF_CSYS_ask_wcs( &saved_wcs );, O3 W) j3 P$ G- Q7 R2 t  q$ k7 F
            /* Move the WCS to the specified plane. This is+ ~; H1 C) \6 @* y$ R: U% W
             * necessary because the position passed to the motion
$ K# @$ ?: e. w9 {5 A7 c             * callback, and the position returned by7 P- t8 _' S" n) ?/ t2 d
             * UF_UI_specify_screen_position, is the screen" E2 u8 K9 _, @# T
             * position projected onto the WCS XY plane.; k2 i- n* ~7 r' q  ~, W( i) G! M* }
             */& l" L. A, B1 h0 D* l7 \7 \
            if (default_plane != 5)
7 m: X- _7 _* t5 t            {
( k7 _* V7 U) [" t1 {1 G                UF_CSYS_create_matrix( plane_matrix, &mtx_id );
* }6 B; x& ?0 s6 {0 y0 \5 v# o                UF_CSYS_create_csys(  plane_origin, mtx_id,
: D- P0 J- h* P' }- C' G+ e0 i                                   &csys_id );
& {8 |8 \$ x: k. ]) c5 c                UF_CSYS_set_wcs( csys_id );
5 e" D# b7 D( B8 F" {8 O            }
; v& K- L( @" t9 H# L            /* Obtain unit vectors and the arc matrix relative to. A, i$ Q$ [1 D+ j" l3 a) K
             * the Work Part coordinate system.. w. G( N" u3 x+ l
             */; O2 t- w% f' r+ ]1 N
            UF_MTX3_x_vec( plane_matrix, x_vec );/ f2 D& V( Q; i$ p4 [% u2 c) u9 ?+ e% A
            UF_MTX3_y_vec( plane_matrix, y_vec );" s3 s3 h* A9 I" \8 q/ T
            UF_CSYS_map_point( UF_CSYS_ROOT_COORDS, x_vec,! J" g, Z7 @! g) ]% u. A7 c
                            UF_CSYS_WORK_COORDS, x_vec );' R, z8 D- O7 d6 ]# J! T
            UF_CSYS_map_point( UF_CSYS_ROOT_COORDS, y_vec,- E( B# r8 H1 n6 r* _) Q
                            UF_CSYS_WORK_COORDS, y_vec );
9 E* ^6 |/ }4 g7 W, {! b            UF_CSYS_map_point( UF_CSYS_ROOT_COORDS, root_origin,
' [- p4 O3 I5 N+ m# w! \  U                            UF_CSYS_WORK_COORDS, work_origin );2 b! u4 e) c. ?1 y7 O
            UF_VEC3_sub( x_vec, work_origin, my_data.x_axis );9 o* M' n# {9 {3 d" v- d
            UF_VEC3_sub( y_vec, work_origin, my_data.y_axis );2 k+ l5 |+ R0 o" @  s' Y" v
            UF_MTX3_initialize( my_data.x_axis, my_data.y_axis,
6 w' I' ~! F) z" E! q2 O7 r                             my_data.matrix );
5 U5 ^- b. F2 t$ U1 [            UF_CSYS_create_matrix( my_data.matrix,2 V! T: v+ F& [, R+ [
                                &arc.matrix_tag );
& ~4 ?9 {6 e8 r0 Z            do6 b+ c& C# k  W% Y9 n9 }
            {
5 o, V. O4 L7 m3 z5 a* i% e. N6 S                UF_CALL(UF_UI_specify_screen_position(
2 M+ {- s. w) v                                "Specify arc center",
$ S- Y0 c$ J) u: `                                NULL,& _! p0 A6 n: s
                                NULL,0 U$ `9 e. ^, w0 L: x8 ^( d8 q
                                my_data.abs_ctr,, m! ]3 B# U: q4 |1 h4 P
                                &view_tag,
7 U4 {, G3 r9 J                                &ctr_resp ));4 Z+ `, H- t3 f% Q7 k; @5 I4 b1 N9 F
                if (ctr_resp == UF_UI_PICK_RESPONSE)
3 [! g5 d6 D& `                {
$ j7 Q0 M; ^) k2 E) i" ]                    /* Map the arc center to the arc csys.( T6 T6 e/ c- d) q
                     */3 D. o& ~- K2 f+ _4 |8 ^0 u7 e
                    UF_MTX3_vec_multiply( my_data.abs_ctr,
2 t6 d- K* o6 I4 [                                          my_data.matrix,9 h3 N8 J& K' p. N& ]  b% \8 s
                                          arc.arc_center );
9 W) E6 \2 n* R0 |2 x0 D7 ?' h                    UF_CALL(UF_UI_specify_screen_position(2 E4 C# V; ?" }, w7 ~' M
                                    "Indicate arc radius",
2 s0 X3 X! o& D, N) x" R2 ]) _- F, Z6 C                                    (UF_UI_motion_fn_t)motion_cb,  o2 m$ D# l" z1 K9 `* x0 r  @
                                    (void *)&my_data,
$ b* S( V, i7 Y0 O* J2 T                                    arc_edge_pos,
2 F5 I+ R, y0 v) m# \: B8 w                                    &view_tag,
( U9 A, m, t2 y. v( B                                    &pos_resp ));
# V! |- o3 g8 s) A& L8 @5 T                    /* If a position was obtained, create the
$ D& b; N  K/ b( [  e5 Y  k" {! }                     * circle.& [7 r- \/ N  c8 G$ r/ i& D2 E
                     */
2 V2 s% w. W; A/ L& ]                    if (pos_resp == UF_UI_PICK_RESPONSE)
; U2 t2 q# {6 J+ S5 H. e& t- e; B  V8 p                    {
( S0 K( C6 \1 Y& P  E# m+ S                        UF_VEC3_distance( my_data.abs_ctr,$ o$ f$ X: V9 ]7 J
                                        arc_edge_pos,
  w3 E. _( \8 w. p/ o( D                                        &arc.radius );/ Q7 O# w# B4 v" }: b" Q
                        UF_CURVE_create_arc( &arc, &arc_id );
' O. G( Q; b4 M- [* Q9 _# o                    }- s9 W5 U6 t9 Q% P9 u6 H
                }
# D) R! f4 g8 c7 O. v0 t4 U; L            } while ( (ctr_resp == UF_UI_PICK_RESPONSE) &&
0 d6 t" k/ M5 g                     (pos_resp != UF_UI_CANCEL)           );9 p, d( X7 o: W2 w# @4 Z
            /* Restore the WCS if it was altered above.
+ j1 ^) ?* x2 h# \             */
4 m/ H, Y7 E! D. B            if (default_plane != 5)/ K  g' X7 o+ d1 H  i. ^2 j& w
            {
& @! G. I4 g  W+ b; N. T                UF_CSYS_set_wcs( saved_wcs );
- D  h8 Y, l6 I. F* C                UF_OBJ_delete_object( csys_id );( S6 M! t  Q0 z% ^
            }# {+ a$ C/ a6 ^* A& c: ]( v3 K
        }
1 u' _; L/ ]) S4 l) p' ^0 y    } while (ctr_resp == UF_UI_BACK && plane_resp == 3);
0 s  j0 n" w- ?, a! q}
  g: ^0 O- N- z+ ?! A, w, _7 b/*ARGSUSED*/
1 g' ?6 k" @* w3 E8 \$ [void ufusr(char *param, int *reTCode, int param_len)
% [. z0 d& p( `5 W0 a3 O{. r% \  c/ e2 g. P& _
  if (!UF_CALL(UF_initialize()))( A7 K2 [1 l+ L5 t6 C% k6 z# a  w. h/ `
  {% G+ q- G; U$ l+ E% Z! _6 N
    do_ugopen_api();- |  E1 d" O, [* ~$ G/ H: H9 F
    UF_CALL(UF_terminate());
+ K8 c- \+ D3 y5 \! q/ s8 _5 L  }1 r& d6 P0 ]% P: y
}2 q. C3 D1 A6 f6 z6 Y+ i- n) n: j
int ufusr_ask_unload(void)
) i# L- r. B5 L  Z* J+ h{
/ B' v8 Q- D, |" _9 ]4 {6 V" R  return (UF_UNLOAD_IMMEDIATELY);
* U8 B: ?9 O% L5 d" E; |! `( D}/ h7 Q& @5 q- F- G1 U
3 |6 p! H" G$ M- u
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了