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

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

admin 楼主

2015-2-9 13:45:19

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

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

x
* P% ~6 A. _: n6 a1 A; e$ U
NX二次开发源码分享:动态画圆,指定屏幕点和向量相关用法
7 m0 _4 O7 I. R8 u. c3 [
& s5 r8 z, H" q( ]6 I) e0 G" T

: F" j- r- |" Q+ V, [; A这个案例很不错的,分享下,程序运行的结果是指定屏幕,拖拉即可动态绘制圆圈!- r5 u  U/ ~; X* V( |( s

$ i/ g+ w4 t& H: `6 _$ o' l#include <stdio.h>
7 Y% e5 d6 a! v) [) \" f#include <uf_defs.h>
1 N& Q/ v+ u/ o$ |: |* h#include <uf.h>
% i0 w, I( d$ G#include <uf_ui.h>
& j6 ~8 J3 ?3 e#include <uf_csys.h>( B  M9 ?; S5 o
#include <uf_vec.h>; D! Y) y) x0 [+ e  Y) N& X
#include <uf_disp.h>
' p$ W# i6 P0 X8 Z3 m6 ~$ F#include <uf_curve.h>9 d1 ?# z7 g3 x& m# ]8 n  @- k
#include <uf_mtx.h>) k7 l) j4 P- |" n/ \! @7 R. ?
#include <uf_obj.h>  @. L+ P+ C  Q: Z
typedef struct  s/ Y+ h: p8 i/ |. z
        { UF_CURVE_arc_t  *arc;
5 Z* K4 X9 E* y2 Y6 N/ B8 e. R3 x          double          abs_ctr[3];
3 i$ p9 i* M7 m0 N5 A7 g          double          matrix[9];
# F+ g5 w2 L" x3 Y  U7 c          double          x_axis[3];
' P. D- k* ~8 H7 Q& M          double          y_axis[3];
7 s1 J: l" Q: C$ {, B        } my_motion_data_t;. l& x* u6 P# w- q/ g
/* Define a motion callback to render a visual representation of. @% J% W4 c2 |. B- Z* c
* the circle to be created, along with a bounding box around the
& x8 }! ^; l& u2 F7 r# r5 g6 c * circle, an arc of radius 1.0, and a "rubberband" line from the
. Q$ V5 p/ o0 }- B * center to the cursor position.+ ^3 h5 D8 ^4 n4 ]0 v9 @
*/6 ^# r* o0 C5 y9 h# m/ L3 E
static void motion_cb( double                   *screen_pos,3 T& J, @! I- g2 N
                       UF_UI_motion_cb_data_p_t  motion_cb_data,
2 M6 j" d& k9 ~4 \% F% q                       my_motion_data_t        *my_data )& Y" S8 S2 U2 v  N
{
  i6 k5 n" }0 V7 a    double radius, pos_array[5][3];
8 L. i. J& k' Z. i  @" A; d    double xrad[3], yrad[3], x_y_vec[3], x_ny_vec[3];
: n  _2 A8 D% H# L: B' {    /* Calculate the arc radius:  the distance from the arc center, R1 o2 I: o/ l6 g5 e
     * to the current screen position.; t; b- i3 F0 U; Q+ m
     */" t9 X8 ]; c9 ^4 O; S
    UF_VEC3_distance( my_data->abs_ctr, screen_pos, &radius );
+ ~" B9 ?+ v, T. F: ^    /* Map the arc center to the "csys of the arc".* j; I7 A$ L6 }: q. u" E
     */# s5 Y4 X) _% T" ]/ y: x
    UF_MTX3_vec_multiply( my_data->abs_ctr,- ?" g# G6 T+ b, e1 M; w3 x3 l6 x
                       my_data->matrix,: B3 ^* P3 P, l( M5 Q
                       my_data->arc->arc_center );8 \* w8 i# u- O. f
    /* Draw a circle and an arc in the view of the cursor.
! c, J8 h8 |" [- H     */
0 W$ Z3 n; }1 ]. i8 F    UF_DISP_display_ogp_circle( motion_cb_data->view_tag,6 u* w  H  W8 ?- Q) [
                            my_data->matrix,1 F% K- t' B/ \$ ]1 O' f2 A+ j6 a4 V
                            my_data->arc->arc_center,( H/ W# ?6 K$ s1 g
                            radius );6 L( ~, x4 ~/ y) t( ^) V' N
    UF_DISP_display_ogp_arc(    motion_cb_data->view_tag,
; B; [  A) t5 `                             my_data->matrix,; s0 ]' p2 y5 p8 b' k
                             15.0*DEGRA, 345.0*DEGRA,
* ]1 y' W9 A1 m                             my_data->arc->arc_center,- K: h* v+ c% U  V
                             1.0 );
8 N8 {& L- G6 M- K    /* Draw a bounding box around the circle.1 o- u; c9 _8 ^" @  M8 _! H3 {
     */
# y, Q+ f2 K; o+ \! B& H/ E    UF_VEC3_scale( radius, my_data->x_axis, xrad );
0 f  W7 n0 n% L/ [9 h3 k    UF_VEC3_scale( radius, my_data->y_axis, yrad );& P4 c* p) y. q, p( D
    UF_VEC3_add( xrad, yrad, x_y_vec  );
& N6 ^9 `: E4 h/ _9 ?    UF_VEC3_sub( xrad, yrad, x_ny_vec );3 n8 P8 e& T! u7 \7 o$ ]5 [
    UF_VEC3_add( my_data->abs_ctr, x_y_vec,  pos_array[0] );
# b- l$ U4 B% \" Q$ V4 s    UF_VEC3_sub( my_data->abs_ctr, x_ny_vec, pos_array[1] );5 g. J3 L5 n: R: Z. W
    UF_VEC3_sub( my_data->abs_ctr, x_y_vec,  pos_array[2] );
/ s2 D: E  m: w& g    UF_VEC3_add( my_data->abs_ctr, x_ny_vec, pos_array[3] );
0 o' A" I$ }3 ~1 L* x    UF_VEC3_add( my_data->abs_ctr, x_y_vec,  pos_array[4] );  _( Y) W, h* c8 e
    UF_DISP_display_ogp_polyline( motion_cb_data->view_tag,' K' N) Y1 Q( P) |. `4 c5 I
                              pos_array, 5 );
+ w8 r% R. f, ]( c) D    /* Draw a "rubberband" line from the circle center to the* Z6 f( [. H! b, R3 n; N
     * cursor position./ e$ K0 D! i2 H# L
     */
& s, x$ `+ ~* R+ ]" O# c- g    UF_DISP_display_ogp_line( motion_cb_data->view_tag," c: T$ h! i6 |( K8 ^# @/ n* `
                          my_data->abs_ctr,
( N- r: I* s0 d! F% b* |6 I0 p                          screen_pos );9 O" z- e2 `2 L( h; V7 q
}
" x+ j/ a% L9 S0 v& }+ i2 l9 S#define UF_CALL(X) (report( __FILE__, __LINE__, #X, (X)))
7 s' Z6 E4 v! \static int report( char *file, int line, char *call, int irc)
5 q" K, |* r* F. o: R0 K{
( g0 y6 S2 {; _- M1 Y  if (irc)# c- e* x/ z& E7 J
  {) p9 i, N9 H' T5 d
     char    messg[133];
3 v8 C3 p( ?) _. m3 X( T     printf("%s, line %d:  %s\n", file, line, call);" G# c( w# R0 M7 a+ t6 p! P8 A4 `7 ]. m
     (UF_get_fail_message(irc, messg)) ?( X% g- c# X: r) P4 X5 u4 |9 h+ @
       printf("    returned a %d\n", irc) :
% d9 C5 h8 r' L/ E- B+ ~       printf("    returned error %d:  %s\n", irc, messg);, w0 Z- ]9 x" q" z6 M
  }  j( A7 t& O) c1 i
  return(irc);
& Q7 @$ h  G+ ]* w1 u4 P( f3 y}' F5 ]  [1 X7 r
static void do_UGopen_api(void)
& i5 O3 l: v7 |1 G: G{
/ L4 I; D9 g7 M& l# e    int               default_plane;
& o; v) a& w! L7 j$ s& t7 {/ s2 g    int               plane_resp, ctr_resp, pos_resp;
' @  o- J; u% ?1 M  D* A3 I/ ^    tag_t             plane_tag, saved_wcs, mtx_id, csys_id,
, {7 {% y6 v! c6 j$ `$ w- p3 Q                      arc_id, view_tag;
  t0 L$ n! l/ s+ l5 i& t& M3 t    double            plane_matrix[9], plane_origin[3],# H6 M/ B1 h+ i9 {5 [* r& X5 Y, `
                      x_vec[3], y_vec[3], arc_edge_pos[3];
! a" X8 F% l; z    double           root_origin[3] = {0.0, 0.0, 0.0};
* U! m! r6 @/ r    double           work_origin[3];
+ V9 u; q5 g* V& L* y" l1 S4 S6 z    UF_CURVE_arc_t    arc;
- i% q2 M9 P  m& Z    my_motion_data_t  my_data;2 f% K& G$ l. x- I
/ \  n0 W  c* p
    my_data.arc    = &arc;
8 N) |6 v& g* x# x2 n2 D    arc.start_angle =   0.0;* j/ s  P2 X! H6 I& \/ v
    arc.end_angle   = TWOPI;    /* Create a full circle. */
8 ^5 g2 v0 ?1 M  e5 Y0 x    default_plane   = 5;       /* Default plane = WCS */0 C+ o& d) i+ B1 m7 p- Q8 Q
    do% j5 j% ~& C& z( j+ O* E$ V7 r
    {! z5 B. p, N! X; q, E0 Z7 _
        /* Specify the plane on which the circle is to be created.1 b6 o) g- N2 Y1 U- i9 t. s3 v
         */
# f6 b" V1 K# t: f# H0 d        UF_CALL(UF_UI_specify_plane(* o+ @. n0 N! b% y7 u
                         "Specify plane for circle creation",. F- \1 ~/ W" V' o" T" U; `
                         &default_plane,
) M2 ~, o+ _$ N  t                         1,0 Q  P( o: A) `- S. V
                         &plane_resp,* j3 T$ q' K3 q8 g  r
                         plane_matrix,9 q. T1 \. o3 {& z
                         plane_origin,5 ^+ |4 Z2 x( ?3 U1 m$ E6 U9 f
                         &plane_tag ));* G7 _! o1 Q' ~( t5 C, P
        if (plane_resp ==3)$ {' C# G) [- t% C# L& P/ K3 a! J
        {
5 O* ]9 Q8 @" J4 `            /* Save the current WCS for future restoration.1 J3 O- {& X+ v" P
             */$ U# b. \+ N5 _* w2 R! R
            UF_CSYS_ask_wcs( &saved_wcs );
1 a* r, b/ T" C0 L# h3 ~/ K            /* Move the WCS to the specified plane. This is
/ z+ `0 q1 y+ b             * necessary because the position passed to the motion5 t6 {$ O, X$ a
             * callback, and the position returned by
3 P" p) [0 ~: H             * UF_UI_specify_screen_position, is the screen8 |4 ^. h7 ]- q7 f7 ^3 B- g
             * position projected onto the WCS XY plane.
! c5 M8 @5 R" ]; }5 ]0 }             */0 w* v; b. Y- L+ D: v6 Q
            if (default_plane != 5)/ y# F+ o. k; X. N; L( f# q
            {
8 U3 ~' Y- M+ p/ z                UF_CSYS_create_matrix( plane_matrix, &mtx_id );
) P/ B4 A) a) r& K                UF_CSYS_create_csys(  plane_origin, mtx_id,
0 S- `0 B8 m1 ?$ Q' V! z* Z                                   &csys_id );
& W5 e0 ]$ \& c6 X( d                UF_CSYS_set_wcs( csys_id );9 _7 M; m2 q4 T+ I7 Q
            }
- u0 U; X  D6 N$ l. j  \            /* Obtain unit vectors and the arc matrix relative to
4 Z1 S1 `) W. y" T& u3 J             * the Work Part coordinate system.
& D3 Q; B1 X: q9 @7 p0 r             */& r: ~5 L% N0 N" ^' N" e/ X% O) G
            UF_MTX3_x_vec( plane_matrix, x_vec );
+ _' v. Z& k# s( F* G3 g            UF_MTX3_y_vec( plane_matrix, y_vec );
4 g, \: f) R. T            UF_CSYS_map_point( UF_CSYS_ROOT_COORDS, x_vec,
' }9 w/ X1 G4 k1 `! P                            UF_CSYS_WORK_COORDS, x_vec );
$ Z+ t0 b9 h7 M9 a! _/ b/ K+ x, ]            UF_CSYS_map_point( UF_CSYS_ROOT_COORDS, y_vec,# ]1 ~1 ^0 {2 s& f4 X
                            UF_CSYS_WORK_COORDS, y_vec );
" k; C, X" U5 r- _$ Q+ A! |3 c# d* f% T6 H            UF_CSYS_map_point( UF_CSYS_ROOT_COORDS, root_origin,' G" i/ @( F! d% U4 V8 N$ [0 S
                            UF_CSYS_WORK_COORDS, work_origin );
4 K( c# b4 U/ Z+ a3 ]( o            UF_VEC3_sub( x_vec, work_origin, my_data.x_axis );
4 W% L- q. B& G5 a            UF_VEC3_sub( y_vec, work_origin, my_data.y_axis );2 o# K9 u* @3 |: ^0 L: c
            UF_MTX3_initialize( my_data.x_axis, my_data.y_axis,
% Y  P2 d8 l; @# M4 |2 d                             my_data.matrix );
" A) g) \" q7 @1 V. {! k            UF_CSYS_create_matrix( my_data.matrix,
- r% p" f$ U" R4 {4 {% J' z                                &arc.matrix_tag );4 E; g, \# O2 j
            do9 b0 N0 Y) t' J0 i
            {/ Z! `% H1 E  M# e  R  E
                UF_CALL(UF_UI_specify_screen_position(
+ x; E) O* g$ `* b, N) V                                "Specify arc center",
2 Q$ {$ |4 q5 x+ y                                NULL,
/ S" R/ s9 q6 \+ q9 d                                NULL,1 a  E5 t/ |& j" w
                                my_data.abs_ctr,# O! E$ ~3 [" G. |% a5 |) P! O% H! k, ^
                                &view_tag," K% |* a& \6 t8 e6 k. g
                                &ctr_resp ));& s3 z6 z1 x* e: ]
                if (ctr_resp == UF_UI_PICK_RESPONSE)" i# h+ z; x2 r1 J7 K& q
                {2 b/ g( S4 h0 x0 `, V' K: c
                    /* Map the arc center to the arc csys.
4 s% c" P6 V  d) Z* X                     */
! |' [' x0 u. P! C* t# n7 j4 _                    UF_MTX3_vec_multiply( my_data.abs_ctr,
* G( I& U. F7 s  p- G. y                                          my_data.matrix," X) }2 v- V7 ], Z  I) V5 @* u
                                          arc.arc_center );
  [5 j% \& X5 r/ Z/ t                    UF_CALL(UF_UI_specify_screen_position(
. R0 W! _+ T9 M; r                                    "Indicate arc radius",' l& e8 x6 @% q
                                    (UF_UI_motion_fn_t)motion_cb,
  g( F3 Q4 Q, W! l( }  C                                    (void *)&my_data,  \* V6 J8 A8 R. F' B
                                    arc_edge_pos,
/ ?% K* d8 Y9 M+ p( d6 q8 h                                    &view_tag,) H% K( h9 F1 K
                                    &pos_resp ));
% M' z$ ~4 j9 Y4 q/ P2 E! J. d+ O                    /* If a position was obtained, create the3 g* ?* k' A$ C; P( d4 Y  f
                     * circle.
, d5 q) q( o3 `  {1 }7 V$ R                     */5 Q2 i6 z7 m+ O/ ^% w  ~. [
                    if (pos_resp == UF_UI_PICK_RESPONSE)# a3 \  W; K% B, j# o, W7 B
                    {- I) E( i0 L4 e
                        UF_VEC3_distance( my_data.abs_ctr,
) {6 u& B# B1 s7 m; E                                        arc_edge_pos,7 y! n( n/ g; x
                                        &arc.radius );- t# p* ?, S% n: U1 ~
                        UF_CURVE_create_arc( &arc, &arc_id );
* a. n- l. A9 ]4 `* c                    }& V- \& F; Y8 ]2 G& a. J" L# u
                }$ ]" A# {# u/ |* q
            } while ( (ctr_resp == UF_UI_PICK_RESPONSE) &&0 C" E% J* g# O* a* B
                     (pos_resp != UF_UI_CANCEL)           );4 L6 E9 R: D. C! b7 q$ B4 v
            /* Restore the WCS if it was altered above.; ?8 J) n0 w) {) X$ r
             *// Q: B3 j! }  s; z: v
            if (default_plane != 5)
- M1 b2 ^- e% K9 I1 B            {
* B* N9 w+ o% U3 f4 K                UF_CSYS_set_wcs( saved_wcs );# S$ `' a. B# w4 v- G, ^7 p
                UF_OBJ_delete_object( csys_id );
: s& S+ m$ {0 G# ]            }3 Z. R2 J7 M- U; p" |% z2 A
        }; L3 [- ?& L' K# E- r& l# e- u
    } while (ctr_resp == UF_UI_BACK && plane_resp == 3);% {, O$ D6 K+ y# @  x8 t
}+ O8 q4 X9 `8 Z) L
/*ARGSUSED*/0 s5 x/ s. w+ u  g- _& c5 A/ }, q& t; B
void ufusr(char *param, int *reTCode, int param_len)* D# q! j3 v3 [3 V5 [; u
{
1 i/ V& v! r# `$ I  if (!UF_CALL(UF_initialize()))* v& v1 p& n6 h( c9 ~: u
  {
$ A* o0 j, ^# @    do_ugopen_api();
" d  l, [3 x9 y$ @( d/ A6 ^    UF_CALL(UF_terminate());
$ h, P3 o8 h! s. o  }8 K) ]9 j  b1 [. c
}, w  V; u: v% Z4 o" g7 f
int ufusr_ask_unload(void)
2 m/ G5 B7 B2 j( _* _2 o{3 N% e* h6 d4 z
  return (UF_UNLOAD_IMMEDIATELY);* B3 S6 A* P' i& i; Z* Y- C
}
6 K% x4 {: [2 S& R# H5 H( ^% F1 T. Q3 t8 @& ^
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了