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

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

admin 楼主

2015-2-9 13:45:19

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

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

x
7 ]* d' |. r! M2 P5 a5 c0 M
NX二次开发源码分享:动态画圆,指定屏幕点和向量相关用法% _/ P; m- M, s0 D! _

& j6 ~# q" n# w5 t: L7 \5 [

2 R$ U) `% V6 z" Y7 H这个案例很不错的,分享下,程序运行的结果是指定屏幕,拖拉即可动态绘制圆圈!
- B! W- R; Q6 V' M5 K: [& S; a5 o; T  _7 W  q" d5 ~( \
#include <stdio.h>- S  w4 U' @) j! |, q+ i6 u
#include <uf_defs.h>1 K/ I6 u$ H# b% y+ j
#include <uf.h>! {% J1 D' v5 X2 {. M2 w3 F
#include <uf_ui.h>
5 a8 l4 o" i3 n# s#include <uf_csys.h>- u. {- S$ d+ T1 [( v" F0 P7 I
#include <uf_vec.h>
8 |! m- _# {9 H0 j# a( ^  [#include <uf_disp.h>
! n. J; T2 _5 \$ I$ g) n! i#include <uf_curve.h>2 u' @6 |' A0 z5 l$ R5 `1 Y
#include <uf_mtx.h>
: D6 ]. S2 l( F; B4 a1 l# ]#include <uf_obj.h>
6 M; _# P0 r3 Ztypedef struct
6 V2 i0 y5 L! _! j5 S        { UF_CURVE_arc_t  *arc;
# K3 t& r% [7 U/ L2 I          double          abs_ctr[3];4 ~4 R: @7 F6 D5 p: \* X, W
          double          matrix[9];
' f! i* m/ t, o) v          double          x_axis[3];4 m- H, T+ ?! A3 T& c
          double          y_axis[3];7 \7 b0 }+ \% x7 o
        } my_motion_data_t;
0 H" ]4 t4 h  V3 a2 ?$ y/* Define a motion callback to render a visual representation of6 m# S9 r* u" ~5 t
* the circle to be created, along with a bounding box around the4 {% J8 t1 ~+ V$ W! x& v( _; h3 V9 p
* circle, an arc of radius 1.0, and a "rubberband" line from the
3 c3 q. d, z$ j2 L3 | * center to the cursor position.
: J: G% M5 S9 I2 A' H' | */
4 a, e7 r1 u9 n: M' istatic void motion_cb( double                   *screen_pos,. S% n* ], r3 U4 d! J! b5 G
                       UF_UI_motion_cb_data_p_t  motion_cb_data,
1 y% l. ]1 J3 S8 Z" J+ |+ J% ?! U                       my_motion_data_t        *my_data )
; `' F1 F9 m; S{; q( Q) E. u+ B+ c
    double radius, pos_array[5][3];0 z% P4 g% L+ ~9 b/ J0 W3 I8 @
    double xrad[3], yrad[3], x_y_vec[3], x_ny_vec[3];
8 e  R% f# X1 \6 S* F    /* Calculate the arc radius:  the distance from the arc center& {& M1 A3 E/ W! ^, b5 L
     * to the current screen position.( p7 Q& l6 ?$ A" B$ p
     */5 v4 s6 ?9 |* Y% F, L8 D
    UF_VEC3_distance( my_data->abs_ctr, screen_pos, &radius );* L' q  D4 v% k3 c+ x, q
    /* Map the arc center to the "csys of the arc".
1 y$ V- A7 F2 H4 ^' z, g     */, J4 q8 y/ w7 V+ H: }6 W2 U
    UF_MTX3_vec_multiply( my_data->abs_ctr,' ~+ a1 ~2 N8 E  e
                       my_data->matrix,
3 z9 g+ {' Q  s% S                       my_data->arc->arc_center );
* p0 i7 c7 I$ z' M8 h    /* Draw a circle and an arc in the view of the cursor.
" I( l' r+ E+ w5 B6 w/ c5 E     */
4 l/ \6 p& n6 j! n    UF_DISP_display_ogp_circle( motion_cb_data->view_tag,
8 i1 P  _& x# K% l8 g6 a( x                            my_data->matrix,
- D+ ]; y) c, ]  b6 E! n7 o6 b% S                            my_data->arc->arc_center,
* P6 x+ E. X7 H, j5 x                            radius );
+ ?5 {; D3 F( d% I$ P0 Z6 G    UF_DISP_display_ogp_arc(    motion_cb_data->view_tag,# S7 H6 ^& R0 h
                             my_data->matrix,2 ~& f! }' ?% y8 f! \
                             15.0*DEGRA, 345.0*DEGRA,2 p2 Q3 Q# a2 X- B# P
                             my_data->arc->arc_center,
( n0 H4 _+ O# W; T& D                             1.0 );* i6 a* B  Z& [
    /* Draw a bounding box around the circle.9 I8 I5 j+ c+ M/ \& d
     */: M3 I6 i0 y3 j+ i# L0 X: O& }% _
    UF_VEC3_scale( radius, my_data->x_axis, xrad );
* |: y- v4 t7 K- i& _9 H    UF_VEC3_scale( radius, my_data->y_axis, yrad );
2 G6 J( J+ N1 \+ E    UF_VEC3_add( xrad, yrad, x_y_vec  );
3 M7 M7 q5 a, j( S, D! q# Z    UF_VEC3_sub( xrad, yrad, x_ny_vec );
$ [5 @% v% |1 n7 k$ t# j" V    UF_VEC3_add( my_data->abs_ctr, x_y_vec,  pos_array[0] );
4 T7 ^3 W, B; A9 C: p5 f    UF_VEC3_sub( my_data->abs_ctr, x_ny_vec, pos_array[1] );: f" J" o/ r; O" K6 O- ~1 K
    UF_VEC3_sub( my_data->abs_ctr, x_y_vec,  pos_array[2] );! N! v! K+ k5 n8 j
    UF_VEC3_add( my_data->abs_ctr, x_ny_vec, pos_array[3] );
( h, f* o& C2 V    UF_VEC3_add( my_data->abs_ctr, x_y_vec,  pos_array[4] );
9 c9 \8 W; v% {0 ^    UF_DISP_display_ogp_polyline( motion_cb_data->view_tag,
" j' s1 b( d0 Q# j                              pos_array, 5 );7 g5 k: o: d' `/ Y# j% B+ j4 y$ h$ _
    /* Draw a "rubberband" line from the circle center to the
, A/ ^6 l% |/ v: z% r6 s% J# J     * cursor position.9 J8 a; v: a& `( r
     */
; w* U4 L: L# }' M    UF_DISP_display_ogp_line( motion_cb_data->view_tag,( @$ H6 [* v2 }& F. u# B
                          my_data->abs_ctr,6 a4 |  f( [+ Z- W) h, |" G" f+ O
                          screen_pos );! D, R5 d' b; V
}( g4 E2 A- p/ f: t
#define UF_CALL(X) (report( __FILE__, __LINE__, #X, (X)))! }0 e) r  ^2 }/ }5 @
static int report( char *file, int line, char *call, int irc)
0 z/ l- {$ ~0 U& O& n3 u{7 \/ a' m: H; K$ k7 ?9 F/ t
  if (irc)
. B9 G3 A0 H. a7 A0 X. b/ h$ W  x+ J  {
' ~% V) y5 e; n6 d, F, K     char    messg[133];
2 [( n7 C3 m4 }0 g9 W$ i$ c8 y" K, H     printf("%s, line %d:  %s\n", file, line, call);
4 t0 K7 `/ L2 O! d     (UF_get_fail_message(irc, messg)) ?
2 s5 [& f& x" T1 L4 p6 }8 Q       printf("    returned a %d\n", irc) :$ t# K  J- T: k! W& K# K
       printf("    returned error %d:  %s\n", irc, messg);3 ^. g; @' T' I; y# V. h
  }
* `  D! l7 q" ~/ i) K$ f  return(irc);  f( M5 c; T$ w7 v: U
}/ N- e8 L8 {" ^) x4 ?- T) I) f
static void do_UGopen_api(void)6 _  |6 a! i6 i. U+ i  a% a. U
{- ~1 `9 D  D  a/ u2 o1 y# m# M7 t
    int               default_plane;; M( [/ z( `4 E, S& H& P% k9 Z
    int               plane_resp, ctr_resp, pos_resp;' e7 T2 K$ V$ z* E' K
    tag_t             plane_tag, saved_wcs, mtx_id, csys_id,- g. w) B. G8 E( I
                      arc_id, view_tag;
) j7 M9 r6 J* p, _3 T& R$ k    double            plane_matrix[9], plane_origin[3],3 w$ Y9 Q# y* T6 M$ t$ q
                      x_vec[3], y_vec[3], arc_edge_pos[3];+ E# e* N4 S6 T. x* j2 ]
    double           root_origin[3] = {0.0, 0.0, 0.0};
4 s7 u2 G6 E0 x# D3 r    double           work_origin[3];6 n! {0 S! e8 Q& _" G# a
    UF_CURVE_arc_t    arc;
+ v3 n) G: U5 i    my_motion_data_t  my_data;
# Z$ C/ y8 F' Z6 `, |: {- r7 u5 w" e
    my_data.arc    = &arc;
2 s5 A! H+ W  S$ T, ^    arc.start_angle =   0.0;: j3 D- ]& j" O
    arc.end_angle   = TWOPI;    /* Create a full circle. */0 A3 P5 k2 s' f8 Y8 |
    default_plane   = 5;       /* Default plane = WCS */5 U$ M2 r+ p4 v8 H5 X! V3 f1 a
    do8 t# T& }( f& G- c1 b; j
    {
+ ~3 J; O! k8 t9 @3 s        /* Specify the plane on which the circle is to be created.
, Y" ?7 \/ \0 b9 m  G) Q         */
' e8 L# W  s* k4 [" |) g! u        UF_CALL(UF_UI_specify_plane(0 ]  W; K" N- Y" `. E0 j: E. b
                         "Specify plane for circle creation",( e" _) i! c( E1 k' q$ k
                         &default_plane,
# \  G+ X/ M' H/ Z; w1 S3 `                         1,
* X* S6 y* P) |2 [! C1 j# j" @                         &plane_resp,' U- }; c0 S) o" f: N1 g( W# q
                         plane_matrix,  @' Y( o" F' k' w$ |$ _2 s
                         plane_origin,4 a7 D# s0 Q/ C
                         &plane_tag ));
; V$ c4 T6 f3 W4 }9 P        if (plane_resp ==3)
1 o! T( X1 G9 i2 b1 F        {
+ e8 F/ ~* ^0 c2 a            /* Save the current WCS for future restoration.1 ~% h- J. E9 A9 x- N
             *// H8 e3 A! t) z
            UF_CSYS_ask_wcs( &saved_wcs );
4 p2 A! {2 \; {/ }% N            /* Move the WCS to the specified plane. This is
) c5 L5 S" _/ w4 H             * necessary because the position passed to the motion+ u  Z4 y& f0 Q8 Q7 D+ u& {
             * callback, and the position returned by$ i( v$ \* V  y* G; P* Z  D
             * UF_UI_specify_screen_position, is the screen
; R% R0 `# I2 k4 U4 I3 z* h             * position projected onto the WCS XY plane.  h7 _& E$ `/ W4 {) S! h% m( ^
             */
* z5 _6 \8 a5 S" {2 d( E3 ^8 o            if (default_plane != 5)
5 R0 l* e. s) J            {* _4 H% u0 i& V+ `; q8 J( U
                UF_CSYS_create_matrix( plane_matrix, &mtx_id );
6 A, E& k$ H7 {2 x9 g- C                UF_CSYS_create_csys(  plane_origin, mtx_id,
( r7 N2 \( P; k4 d/ i& t                                   &csys_id );# A# p4 R  ?  O' J  [
                UF_CSYS_set_wcs( csys_id );
: D! E- E$ x# f+ L            }
7 u6 ?2 ?  [/ {2 l) g            /* Obtain unit vectors and the arc matrix relative to: \9 w" }$ K( H. i* n! {2 n+ y
             * the Work Part coordinate system.2 o. n8 i! e# \+ ^: ^# P/ I7 p! [
             */
, H9 F; M+ T% R4 x            UF_MTX3_x_vec( plane_matrix, x_vec );0 u3 Z$ t/ ], s
            UF_MTX3_y_vec( plane_matrix, y_vec );7 \6 Y7 M5 Z5 `, g: ~& Y; P3 K
            UF_CSYS_map_point( UF_CSYS_ROOT_COORDS, x_vec,& u) `7 o" i. L4 C8 S. D0 R
                            UF_CSYS_WORK_COORDS, x_vec );9 X! w8 ^  {) `1 K2 ^# F; c0 A' V' y. \4 ?
            UF_CSYS_map_point( UF_CSYS_ROOT_COORDS, y_vec,
' T! [6 g5 Z4 V' I5 _                            UF_CSYS_WORK_COORDS, y_vec );2 q8 A/ }2 u/ L6 |0 d9 F  e( A
            UF_CSYS_map_point( UF_CSYS_ROOT_COORDS, root_origin,6 p7 x) J8 g: R+ k3 V* n4 k
                            UF_CSYS_WORK_COORDS, work_origin );
4 i& A; v; _( s2 x+ E$ \8 E7 w$ N! _            UF_VEC3_sub( x_vec, work_origin, my_data.x_axis );  A3 T1 D! |5 }% ?
            UF_VEC3_sub( y_vec, work_origin, my_data.y_axis );& s) C$ g4 @0 I* T( G
            UF_MTX3_initialize( my_data.x_axis, my_data.y_axis,# h6 _. ?  S/ ?5 h& C; Y6 n: p1 B
                             my_data.matrix );
9 f' S2 y7 a1 H( n  M4 V6 L6 h            UF_CSYS_create_matrix( my_data.matrix,
8 }- D. ?% z5 U, W5 y                                &arc.matrix_tag );
) E6 E' V4 y- D6 k% q            do
( t, `/ l' N' `            {
3 A. W3 v# K& \. Q" X5 T                UF_CALL(UF_UI_specify_screen_position(% B, p5 Z# x# T. c1 b$ p
                                "Specify arc center",
  b, s' q3 Y; G% Y                                NULL,5 S" _3 e* S1 Y. }1 F, |
                                NULL,
4 \. e. g+ J& b* ^1 W                                my_data.abs_ctr,
+ b& E: i- Q1 {                                &view_tag,
/ B: S7 B, o( {0 s, i                                &ctr_resp ));
) Y& ~; e6 D4 n6 _+ v0 Y! _                if (ctr_resp == UF_UI_PICK_RESPONSE)$ @) ]6 A8 o& y' E- d
                {/ ~# u' w& s& n6 b1 c/ \
                    /* Map the arc center to the arc csys.
- d* |- m+ j) y  W) Q  `" t                     */# s  V# X- N( R( c& i8 v
                    UF_MTX3_vec_multiply( my_data.abs_ctr,
9 \4 }7 _+ A" M* j9 w                                          my_data.matrix,
( F  k* s5 G% i                                          arc.arc_center );: N. A/ R5 I% O0 B
                    UF_CALL(UF_UI_specify_screen_position(9 p7 [$ e7 f' x4 e0 {7 W$ @& c
                                    "Indicate arc radius",8 c! B6 P$ k; u; u5 D
                                    (UF_UI_motion_fn_t)motion_cb,9 Q/ H7 Z: y/ d3 t5 i
                                    (void *)&my_data,
" a$ h& }1 I; H, @                                    arc_edge_pos,
! q) `) x, R5 ?8 V+ X" D; y                                    &view_tag,. v0 i, A' Y7 T$ e" w4 z  D, J6 |
                                    &pos_resp ));  Y! O1 H% `$ m4 ]
                    /* If a position was obtained, create the; a" Q0 C- {( ]- o
                     * circle.1 K; r. ?8 W$ R- p8 [0 }
                     */5 u2 w" P3 G3 g" a; B
                    if (pos_resp == UF_UI_PICK_RESPONSE)
+ H7 a% [% Y. t/ L                    {
2 n7 {& X$ [/ _2 Z. ?; Y                        UF_VEC3_distance( my_data.abs_ctr,
; N6 [' W# C4 O% o                                        arc_edge_pos,! G2 J3 r" \, J4 q
                                        &arc.radius );
, m& G' V7 F5 f/ W& u# O% V7 I                        UF_CURVE_create_arc( &arc, &arc_id );
  @- Y7 u* m8 r$ @* q                    }$ \) I$ L9 z- p
                }6 H9 o' k* p9 w4 ^8 N+ g
            } while ( (ctr_resp == UF_UI_PICK_RESPONSE) &&" g3 z9 J. s1 _  i
                     (pos_resp != UF_UI_CANCEL)           );3 Y6 g1 o& E: ~  I8 O3 b' G2 [# D
            /* Restore the WCS if it was altered above.
! ~1 v! q( V/ y. D! `* w             */
0 E" C3 N, [( L8 _+ D, o+ I) D            if (default_plane != 5), W5 M/ z# w. ^5 L0 c
            {
. T; k9 M; ~* O. B) ]                UF_CSYS_set_wcs( saved_wcs );) u" S7 c7 J2 e* `
                UF_OBJ_delete_object( csys_id );6 k/ ~, p- R. Z+ G9 W8 ~; F
            }( ~; \! z! l4 d" Q
        }& V7 q2 ^  d# [5 @
    } while (ctr_resp == UF_UI_BACK && plane_resp == 3);( R* A, g, a, M" Q
}
; S. _- L' m( D1 [/*ARGSUSED*/0 T* F! G& V, k. s4 d, G
void ufusr(char *param, int *reTCode, int param_len)5 y+ Z* l1 v/ x' ]4 G5 |% j
{; \! x$ Z* j) C9 h
  if (!UF_CALL(UF_initialize()))
7 ]% b* \0 R! r9 i+ O0 q& K8 S; @  {8 C' @1 o3 X9 V$ r; U
    do_ugopen_api();
5 g* Q' ]1 P& N' V    UF_CALL(UF_terminate());; e5 a6 T: ~7 m% h8 z, R+ Z
  }
+ R. z: }' f$ C- [  n5 V& B- o# u}. v$ @- \/ D5 C- V
int ufusr_ask_unload(void)
9 r8 X/ J) d# W, b8 C; e{6 E* t, V6 {1 {" \/ [# `  Y/ e$ b
  return (UF_UNLOAD_IMMEDIATELY);
% c& Z, A0 p/ m& a: d1 U}
' P( K  p1 f7 z$ H' p: I$ J3 ^7 @% m
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了