|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
' ~ f2 k, ? E- Z3 }/ y
#include <uf.h>
# v: t9 E' W7 H. {#include <uf_ui.h>0 P C/ f* |- b: H, D
#include <uf_exit.h>5 o3 }, Z$ y) Y, k% ~2 a$ A7 i& t! b& f
- u: E- |- {/ Y' u#include <stdio.h>4 U& K" m, g3 M0 k. x( J) R0 F1 c+ M
#include <uf.h>& a% k) J# J; E* k* l, ^
#include <uf_ui.h>+ ~- v: `1 o# S$ K" z- p# \, q
#include <uf_exit.h>
+ i" Y; i7 ] d- ?1 z2 t% C#include "uf_layer.h"
8 `5 V; ~+ C( r! c#include <stdio.h>
* f% Q+ Q' O+ m7 M- k. ^#include <uf.h>; l9 j* r5 U, Z0 E( c5 j
#include <uf_modl.h>( E6 P7 b. K* ], h1 q6 y. I8 b
#include <uf_curve.h>
/ r6 r) F" s! @; ]$ g5 s#include <uf_csys.h>6 k% s( S2 g5 a7 p8 r
#include <uf_object_types.h> |/ X$ X% f- X+ ]: _; j3 j* N
#include <uf_ui.h>
: b3 r" l$ a/ U9 Y) h8 x#include <uf_part.h>2 F0 }4 s. E8 ^, V6 [
#include "uf_obj.h"
& T: D- K- y4 y& _, Y" w#include "math.h"1 |1 m( S k+ U' ~1 ?
0 P& j5 z D2 R* astatic int init_proc(UF_UI_selection_p_t select,void* user_data)0 _ U8 r' _( j
{
, [! g8 g2 |" r1 e int num_triples = 2; //只选择一种类型4 o% @, B1 v' y/ ~' ^+ I
UF_UI_mask_t mask_triples[] = {UF_cylinder_subtype,0,0,% m) ^ v7 T0 D. |, Q7 E% y
UF_bounded_plane_subtype,1,0};
9 @7 w% q7 ] B if((UF_UI_set_sel_mask(select,
" v# p* p: Y* O2 i q UF_UI_SEL_MASK_CLEAR_AND_ENABLE_SPECIFIC, L8 v6 m0 g: W7 @' s
num_triples, mask_triples)) == 0)0 X/ t8 t/ s! N! | \, F
{5 Y6 u8 P+ [. P* u1 R
return (UF_UI_SEL_SUCCESS);
o5 s9 b( Q2 l7 s& ` }
8 e: k2 V; J: [2 s' A, w+ g5 Q else
' g5 m! `$ A# M {" M3 Y2 k9 i, }6 E$ d5 ^! q6 f
return (UF_UI_SEL_FAILURE);
6 M4 q$ j0 {3 C" N7 G/ z' o2 R }
) \0 n' O& X+ O) ~+ ~}; _ R& M8 v7 l8 e: [' \& W
3 _. }. G( ?2 O0 q/ P( D9 U& j
3 U c+ j7 o$ ~7 w3 o
static void Create_Center(void)0 G$ K; s+ ? j D7 k0 U) T- s
{
( O: v4 _* {" j* `$ [6 v tag_t user_wcs;2 W. G @, Q6 K0 D+ x
UF_CSYS_ask_wcs(&user_wcs);# M( r( x" x8 W. R
char cue[] = "简简单单:请选择单个平面";
' G+ f5 Z2 t( K" X char title[] = "简简单单:对象选择对话框";
3 C& A( }3 j1 }" c: U9 b' K( @ int response=0;* L5 H/ u% ?# o: O6 _, d; A9 R
tag_t object;
3 Y: E% X, O+ G. n7 M( Q int count=0;1 `1 M4 a+ M& N/ P
double cursor[3];( d' m7 l2 g8 }% F/ Y* |1 |
tag_t view;
! [4 r9 c R& p1 M, `l10:# U! _& B( w, S( Y
UF_UI_select_with_single_dialog(cue,title,0,init_proc, NULL,&response,&object,cursor,&view);9 \6 Q$ l% L! R o
if(response==UF_UI_BACK) return; //如果点后退就跳转到L10
3 E6 L: q% g, g z8 p if(response==UF_UI_CANCEL) return; //如果点取消就退出) q: K: ?* @+ v5 X& ]
UF_DISP_set_highlight(object,0); //取消高亮显示- ^: T+ B4 j) y D. g, T% Q
$ \7 z) _- @* U- j int type;
' @- H. E# h: W* Z0 Y% z double point[3],dir_z[3], box[6];& _$ h; Z! V4 x4 ^- Z- q- i
double radius,rad_data;
8 v; [0 y) o) A1 o int norm_dir;6 W% A6 k, W; ^, |* q1 f/ y% d
UF_MODL_ask_face_data (object,&type,point,dir_z,box,&radius,&rad_data,&norm_dir); //得到面的法向norm_dir,+1为正向,-1为负向
5 t+ J/ [. [& Y5 t
9 D$ C3 F0 j' D2 @/ Q* O9 G* a L$ ^& v$ F* m9 q( v7 s. h8 v4 g2 A
tag_t matrix_id;
/ ?8 q4 m* y- i tag_t csys_id;
2 _& \& d/ T+ S2 F* P double matrix_values[9];* H& @: Y0 l$ e5 y) ]( H& M% |* B
UF_CSYS_ask_matrix_of_object (object,&matrix_id); //得到面的矩阵ID) g, u" f1 A4 `7 [8 q4 n9 m, E
UF_CSYS_ask_matrix_values(matrix_id,matrix_values); //赋值给matrix_values X: q8 q9 n B6 X2 e* |0 e1 S
if(norm_dir<0) //判断面的法向是否相反2 _/ O( Z6 @2 p
{
% t2 O/ F8 i5 } matrix_values[3]=-matrix_values[3];+ A. e/ c' n2 Q- y- i% C3 I: h$ Z+ x
matrix_values[4]=-matrix_values[4];
# ]+ o9 J& T0 p matrix_values[5]=-matrix_values[5];
" g, |0 u3 @* M3 |% h% M# R matrix_values[6]=-matrix_values[6];
6 |4 X" P, t# v) G9 d/ @% z0 Q matrix_values[7]=-matrix_values[7];
+ G$ b8 b/ H% B# `6 x, `6 u& Y matrix_values[8]=-matrix_values[8];; M1 Y0 e( k; x" ?2 ]
UF_CSYS_create_matrix(matrix_values,&matrix_id);
( t& U9 |' Y4 N+ _( L. y. N d }8 t- |% C F2 u o8 a. ^: V8 {5 s* f9 p
UF_CSYS_create_temp_csys(point,matrix_id,&csys_id);8 m9 [% Y9 v" s
UF_CSYS_set_wcs(csys_id); //设置面的坐标系(位置不一定精确,可以通过后面修正)6 m5 z6 c& d. u: N3 i! t* W" I
UF_CSYS_set_wcs_display(0); //不显示坐标系(解决显示移动)6 `8 U4 u: v5 O* _* r' i3 ]
! ^+ F5 ~# Z! _2 n
double boundingbox[6];
2 z* r7 d r2 J6 c8 T double boundingbox2[3][3];7 W- Q: o. t0 ^7 b" {% x1 m1 ]
double boundingbox3[6];. {1 C) p* l! E* c
UF_MODL_ask_bounding_box_exact(object,csys_id,boundingbox,boundingbox2,boundingbox3);# O& S, h% ?) L
9 o2 o% S! K% B% t. s if(type ==UF_cylinder_subtype)
" O# g8 Y, P# j m' d {+ ~0 z- H2 y3 ^) p! I$ H6 R
double cyl1_pt[3];
) I% }$ _& k* [, w3 O6 ? tag_t cyl_line,cyl_pt;
% u9 A( R0 [) k( k; ^9 v, N UF_CURVE_line_t cyl1_line_coords;
1 F, |. G7 \: [, U/ D7 @ double WCS_pt[3];
9 f2 v S+ M U1 C UF_CSYS_map_point (UF_CSYS_ROOT_COORDS, boundingbox,UF_CSYS_ROOT_WCS_COORDS, WCS_pt); //绝对坐标转wcs
1 t2 g) ]2 M% ?* C UF_CSYS_map_point (UF_CSYS_ROOT_COORDS,point,UF_CSYS_ROOT_WCS_COORDS, cyl1_pt); //绝对坐标转wcs0 y( C; T7 A, r+ {4 D
cyl1_pt[2] = WCS_pt[2];
' y" E: O3 y, ~9 m- C
: t. B" W& s ~: p' k0 ~ cyl1_line_coords.start_point[0] = cyl1_pt[0];: E" m6 o0 q' Y1 o
cyl1_line_coords.start_point[1] = cyl1_pt[1];
, P' v4 B2 J/ ?4 B+ X5 N4 U cyl1_line_coords.start_point[2] = cyl1_pt[2];
6 S2 b: ~6 k7 D' y5 K: X- b6 |1 R6 Y% Y7 L3 ?
cyl1_line_coords.end_point[0] = cyl1_pt[0];/ c* s# z6 `# Z9 Z, m/ L" m5 v- w
cyl1_line_coords.end_point[1] = cyl1_pt[1];; w1 q T1 J. I" A+ u7 N P( E
cyl1_line_coords.end_point[2] = cyl1_pt[2] + boundingbox3[2];" L) Y& S* }; j q# v; n' P, [
9 |: r' b$ y% l9 l3 c5 ^ UF_CSYS_map_point (UF_CSYS_ROOT_WCS_COORDS,cyl1_line_coords.start_point,UF_CSYS_ROOT_COORDS, cyl1_line_coords.start_point); //wcs转绝对坐标3 {+ H4 { h9 I8 S5 t
UF_CSYS_map_point (UF_CSYS_ROOT_WCS_COORDS,cyl1_line_coords.end_point,UF_CSYS_ROOT_COORDS, cyl1_line_coords.end_point); //wcs转绝对坐标
4 l) V3 f: b% f* r4 L ! G) r3 E0 O* ?- f
UF_CURVE_create_line(&cyl1_line_coords,&cyl_line);
7 u1 @0 g( V) a" \/ }1 l UF_OBJ_set_color(cyl_line,186);4 M! l6 W8 P5 Z$ ?1 C
UF_OBJ_set_font(cyl_line,UF_OBJ_FONT_CENTERLINE); //设置线型: e1 P* Q/ J$ r0 R6 V
: }" W/ @0 ^+ v' a+ ` UF_CSYS_set_wcs(user_wcs);
- ~$ J3 c3 c* a% }& O9 B8 v UF_CSYS_set_wcs_display(1); //显示坐标系(解决显示移动)
( S g* s* D8 t W2 c( C7 z
- z" r% N* z- q. l; d& F goto l10;
3 ^) x4 U2 I W& j4 y }
1 ]+ l) s" L/ U( e
2 B8 b- e! {5 `0 }- n
! r' [/ r# f! G& d" ^( u& O double WCS_pt[3],center_pt[3];
( D0 U% [$ k$ D" I* F6 t. c x tag_t xp1,xp2,yp1,yp2,c_pt,Xline,Yline;" C5 k$ u% w: O
UF_CURVE_line_t Xline_coords,Yline_coords;
" Y: H, I/ n7 K2 Q; O3 ] UF_CSYS_map_point (UF_CSYS_ROOT_COORDS, boundingbox,UF_CSYS_ROOT_WCS_COORDS, WCS_pt); //绝对坐标转wcs
9 B4 }; k0 w2 T \4 m2 f
3 V# o, C, |& t6 r ^- ^ center_pt[0] = WCS_pt[0] + boundingbox3[0]/2;
4 i/ k: ]* P6 q3 A7 ^' a center_pt[1] = WCS_pt[1] + boundingbox3[1]/2;" D6 Q5 z3 P. X
center_pt[2] = WCS_pt[2];6 s6 n: f/ _" O
8 a# O8 i$ L: L
8 c! K5 U, I, c6 ^
Xline_coords.start_point[0] = WCS_pt[0] + boundingbox3[0]/2; //X方向wcs的值+面X方向的大小1/2" s R6 t# B* o& ^! P: m
Xline_coords.start_point[1] = WCS_pt[1];+ n2 I( t9 }$ D' [2 L$ D
Xline_coords.start_point[2] = WCS_pt[2];/ T* Y7 {! s/ I% Q1 F
UF_CSYS_map_point (UF_CSYS_ROOT_WCS_COORDS,Xline_coords.start_point,UF_CSYS_ROOT_COORDS, Xline_coords.start_point); //wcs转绝对坐标 o6 J( A1 X+ [9 {: a$ C5 T
// UF_CURVE_create_point(Xline_coords.start_point,&xp1);
" j% e* _6 V$ K" i$ y# `9 O) B
( A8 |6 x! w; s2 o0 |" K& W8 D Xline_coords.end_point[0] = WCS_pt[0] + boundingbox3[0]/2; //X方向wcs的值+面X方向的大小1/2
& q% }; Q5 r2 V' v5 G1 t Xline_coords.end_point[1] = WCS_pt[1] + boundingbox3[1]; //Y方向wcs的值+面Y方向的大小) c& M* j* o! k6 u
Xline_coords.end_point[2] = WCS_pt[2];
$ z1 I, t4 D( z/ U" x: N P5 C. w UF_CSYS_map_point (UF_CSYS_ROOT_WCS_COORDS,Xline_coords.end_point,UF_CSYS_ROOT_COORDS, Xline_coords.end_point); //wcs转绝对坐标$ l' T& o' Y2 W9 i
// UF_CURVE_create_point(Xline_coords.end_point,&xp2);
7 I% M( e( ~ `$ u
# U# s6 Q B" \) o0 B1 F Yline_coords.start_point[0] = WCS_pt[0];0 [- F+ ?( v( O; v6 ~) N! R
Yline_coords.start_point[1] = WCS_pt[1] + boundingbox3[1]/2;
$ l8 a% l5 Y0 o3 u% ?5 V' k Yline_coords.start_point[2] = WCS_pt[2];2 |/ R: e6 `( p, D
UF_CSYS_map_point (UF_CSYS_ROOT_WCS_COORDS,Yline_coords.start_point,UF_CSYS_ROOT_COORDS, Yline_coords.start_point); //wcs转绝对坐标5 \! @0 o* l/ e) b: s# R
// UF_CURVE_create_point(Yline_coords.start_point,&yp1);
# M2 s- b% H9 X& U5 Z8 p: J, G9 z8 K* w5 X8 E3 Z% ^3 g
Yline_coords.end_point[0] = WCS_pt[0] + boundingbox3[0]; //X方向wcs的值+面X方向的大小
' c5 }7 u& L. n; g6 P Yline_coords.end_point[1] = WCS_pt[1] + boundingbox3[1]/2;3 g, E3 `8 ^9 U8 M+ \
Yline_coords.end_point[2] = WCS_pt[2];
0 W$ Y8 r' @/ B/ K/ e A UF_CSYS_map_point (UF_CSYS_ROOT_WCS_COORDS,Yline_coords.end_point,UF_CSYS_ROOT_COORDS, Yline_coords.end_point); //wcs转绝对坐标
) e7 U0 |+ L& _" b1 C6 I6 S% U! k+ r/ x// UF_CURVE_create_point(Yline_coords.end_point,&yp2);- M( B% p: |* p9 Q1 R5 n
& M3 U) O, B3 ~
UF_CURVE_create_line(&Xline_coords,&Xline); //创建中心线
+ c& b$ f: K* ]0 K- h. I% ^6 {/ }, L UF_CURVE_create_line(&Yline_coords,&Yline);
1 l: o* |5 O$ Z2 ]9 d, M4 L UF_OBJ_set_color(Xline,186); //设置颜色
$ s) W4 T9 x' |5 w! Z; ^, H UF_OBJ_set_color(Yline,186);
) d1 h: V% ^" w& V8 \1 H) a UF_OBJ_set_font(Xline,UF_OBJ_FONT_CENTERLINE); //设置线型5 ^# |) g' p! Y* `4 K3 j6 ?
UF_OBJ_set_font(Yline,UF_OBJ_FONT_CENTERLINE); //设置线型. j& ^% Q) [! O4 U" [ H! P9 `
3 i4 b9 R! F+ u; T
UF_CSYS_set_wcs(user_wcs);1 X- G' v) b4 K. U# o8 C" \1 m$ O
UF_CSYS_set_wcs_display(1); //显示坐标系(解决显示移动) Y4 A5 V9 H" v; S/ V) Z: \& T" }
goto l10;
+ G1 y# N3 m( j- }* B% }7 y6 U! J! @ I
}" h! z' l$ `8 r! {, g/ N5 q4 N
z& f, r! v" s
extern DllExport void ufusr( char *parm, int *returnCode, int rlen )
6 c" K% c" _; v; D{ y" |& B) V# f/ ^7 A5 X- |3 x! F
/* Initialize the API environment */
9 Q3 Y$ z( y2 r& n' q0 ^ if( UF_initialize() )' r% \8 p! W/ l) ^* _* t
{6 ]" F" X& _; q' A/ H
return;
2 A; ]- K Z0 z/ I! V6 c }
# }9 T6 c4 [2 X5 y* k7 h* T9 F
; i" U7 b( H5 {; T, m3 M2 k Create_Center();4 s# c" v8 W+ i& Q+ W" U" [, k# N2 R
8 U6 ~7 \: \+ t7 Z* |) Y7 l
UF_terminate();
/ i5 A4 R4 s: T! H4 x& y}+ z f! ^0 B( ]: C" L
7 D2 r: @- P1 w, C2 k5 {
+ g* M. G# r0 ?8 p+ S3 K S* S/ nextern int ufusr_ask_unload( void )
, j1 ]" E2 |" s0 L{
6 l* d# J0 F+ n9 }2 h) ~; O; n return( UF_UNLOAD_IMMEDIATELY );. ]4 |0 k. N7 p6 t. Y
}
7 A, ]0 V& I' o4 ^% B+ C9 |' ? `. T. W# W! ]! x
! H. Q# R* f, G) X6 q2 ~& r5 b1 ~+ L
) @! p6 X( w' p- h! M+ N, l( \ |
-
|