|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
/ A6 q& A- `# ]4 e O, h5 w#include <uf.h>
% Q! s1 N: h$ t; K( |#include <uf_ui.h>
8 A; [5 m2 M! U5 f$ _$ B$ V#include <uf_exit.h>
: @2 @, ~( S* l+ ~: ^0 y
" D$ D6 R3 \2 I3 V* T#include <stdio.h>" B7 \5 L* Z# o2 Z) Z4 ]
#include <uf.h>' g" ^; w3 T- D5 ?
#include <uf_ui.h>
3 j( w* [, ?. W3 R#include <uf_exit.h>- _+ O, ]; h# N* a: }% W8 a
#include "uf_layer.h" k0 H- F" y* H8 g
#include <stdio.h>
4 r$ B4 T5 J1 E" B4 C. f#include <uf.h>! ~) o- f @5 Y+ M4 e
#include <uf_modl.h>$ X+ I- X# @6 ^9 X
#include <uf_curve.h>
1 Y& W2 v/ T9 Q- q& I. Q" `' c#include <uf_csys.h># F2 T( w2 c* @4 {. N
#include <uf_object_types.h>8 j4 W1 E: E& r4 h7 |0 ^9 _! u* b
#include <uf_ui.h>4 y, N% a) _0 u
#include <uf_part.h>
$ ^/ b# p! |3 y8 J/ _#include "uf_obj.h"$ \0 F* i0 W0 j/ F' T7 A G
#include "math.h"3 c- ]4 K% J8 U
! `3 Y9 n8 b6 z0 ]" P" y$ t
static int init_proc(UF_UI_selection_p_t select,void* user_data)
+ @9 ?2 ]5 Z# e5 Z" N% ~5 ?{
; [7 B+ J1 X% o: \6 ? int num_triples = 2; //只选择一种类型5 w) \( e D" U9 M0 S
UF_UI_mask_t mask_triples[] = {UF_cylinder_subtype,0,0,* x& W0 W, z" ?6 m7 N
UF_bounded_plane_subtype,1,0};8 i6 F$ q8 w2 [. ^5 t/ t: z
if((UF_UI_set_sel_mask(select,
0 R/ H3 n$ I' d1 K7 a' I UF_UI_SEL_MASK_CLEAR_AND_ENABLE_SPECIFIC,
8 O3 E, }8 F6 w S# U0 x/ ]" e num_triples, mask_triples)) == 0)
0 K; C8 v4 w+ T; m! x {' t3 w2 ?# @' `; Y( C Z
return (UF_UI_SEL_SUCCESS);
+ K% G9 O3 M M }
6 e% y( [) U+ X! S. ~ else# `$ k p2 r! v! L6 y' x6 U
{$ k! C2 H Y4 k& V2 Q
return (UF_UI_SEL_FAILURE);
5 W# Y( w6 s$ n7 L }4 m5 }$ }& U# I8 R- r) ?
}
3 D# F* F4 e( H& a+ n+ y0 p1 N# t. z
/ T" _+ c& s, Z, C5 s* Y: n
static void Create_Center(void)/ n' M: R4 n3 p8 c: b
{
7 y C; t% _$ R tag_t user_wcs;
! e2 V# l' J# F& j UF_CSYS_ask_wcs(&user_wcs);
4 A3 p$ Q- I" O4 t char cue[] = "简简单单:请选择单个平面";- E2 N2 u1 S, y n9 a* |
char title[] = "简简单单:对象选择对话框";
; Z3 y2 y, }" V0 D6 ]. d; u7 G int response=0;
" |% ~0 u/ i: d! n- r9 V" @2 G tag_t object;5 r& n8 ^0 ~- H; c) ]3 q1 G& \( C
int count=0;
2 Q3 I$ D& Y( t" Q8 `' g double cursor[3];+ \8 z4 t' u: f/ ~5 i7 |* l" j
tag_t view;. p( F$ ?8 o5 l
l10:+ ~" B5 z7 R3 P/ Q3 h1 h
UF_UI_select_with_single_dialog(cue,title,0,init_proc, NULL,&response,&object,cursor,&view); o# q8 l% q2 F* W1 G
if(response==UF_UI_BACK) return; //如果点后退就跳转到L10* R0 y+ H- k' V5 P
if(response==UF_UI_CANCEL) return; //如果点取消就退出
# F' C' q& g, X, h: b UF_DISP_set_highlight(object,0); //取消高亮显示
" N1 U; S; [) g5 q( D
5 N3 ]) I& ^& } ]: [" l int type;
8 ?/ x7 C( x8 ^/ x1 J) R double point[3],dir_z[3], box[6];
1 F7 Y# V) L4 n `7 Z( @ D double radius,rad_data;; I5 c7 H1 d/ K, u) V9 E
int norm_dir;
" Z! O: H. P* g UF_MODL_ask_face_data (object,&type,point,dir_z,box,&radius,&rad_data,&norm_dir); //得到面的法向norm_dir,+1为正向,-1为负向7 u# {+ a$ D7 O. a1 m- Z
$ C# ^+ _9 M+ S n& v
6 h# q( Y. m1 r( T8 H8 a9 _
tag_t matrix_id;- g4 D$ |7 @5 {2 W8 h& b: Z8 N( ?
tag_t csys_id;7 Y8 }" e6 i, v
double matrix_values[9];
* z, F% V4 ?5 `0 c UF_CSYS_ask_matrix_of_object (object,&matrix_id); //得到面的矩阵ID
; A9 B/ \& m8 s UF_CSYS_ask_matrix_values(matrix_id,matrix_values); //赋值给matrix_values5 `0 T* z A' G: _- H, H$ _. _
if(norm_dir<0) //判断面的法向是否相反6 T6 N6 r' ?( V' |% p
{
& E# @/ H! h% O5 E/ z+ {" y matrix_values[3]=-matrix_values[3];
+ K, |2 {2 a d, t( q7 G% v matrix_values[4]=-matrix_values[4];
1 j I8 ]; ^& B' |- ? matrix_values[5]=-matrix_values[5];) n- s: S; J9 h5 }5 X" G# W/ M
matrix_values[6]=-matrix_values[6];
$ w( Y1 G! g2 ~6 b/ l+ a matrix_values[7]=-matrix_values[7];
" p- g% K, v. w R4 |' M2 B matrix_values[8]=-matrix_values[8];9 [) R3 x- K4 |1 y& v
UF_CSYS_create_matrix(matrix_values,&matrix_id);/ G# |0 }8 w" f2 L q0 c% l7 V! r
}
, E2 Z6 G' ^3 ~2 |- F. Y7 D) B UF_CSYS_create_temp_csys(point,matrix_id,&csys_id);
+ Z3 [0 v0 B0 \' G; ^5 w UF_CSYS_set_wcs(csys_id); //设置面的坐标系(位置不一定精确,可以通过后面修正)
5 T8 H0 o7 g( F' X! b UF_CSYS_set_wcs_display(0); //不显示坐标系(解决显示移动)6 X) f& q- W- r8 y
4 @# C+ X# u* I2 V; V
double boundingbox[6];( f7 ?* v/ ]2 u8 h+ {! Y3 f
double boundingbox2[3][3];8 m, Y, X4 G1 o6 F* @# S z0 q
double boundingbox3[6];: r7 B2 w5 K( H
UF_MODL_ask_bounding_box_exact(object,csys_id,boundingbox,boundingbox2,boundingbox3);
8 O0 @, p6 {, v0 H% i, ?
6 v7 g3 v; h, H3 ?) z if(type ==UF_cylinder_subtype)9 w8 t6 D- \9 v* L% y' l! M0 h
{
; `3 X9 |, [/ ?: Y1 }: o double cyl1_pt[3];; a3 N1 j# R* ] k
tag_t cyl_line,cyl_pt; m. d7 t% } d& h
UF_CURVE_line_t cyl1_line_coords;$ r8 X$ L0 ]6 L
double WCS_pt[3];( J6 g( q5 `$ v; M( Y
UF_CSYS_map_point (UF_CSYS_ROOT_COORDS, boundingbox,UF_CSYS_ROOT_WCS_COORDS, WCS_pt); //绝对坐标转wcs- X9 E1 ]8 C8 [: ^9 @9 \
UF_CSYS_map_point (UF_CSYS_ROOT_COORDS,point,UF_CSYS_ROOT_WCS_COORDS, cyl1_pt); //绝对坐标转wcs2 K! E5 X3 }1 q
cyl1_pt[2] = WCS_pt[2];7 N6 m5 N) I* q3 m' n% \
t; x, P1 P u6 j$ |+ a
cyl1_line_coords.start_point[0] = cyl1_pt[0];
9 f* O, B5 s9 e cyl1_line_coords.start_point[1] = cyl1_pt[1];0 r5 l' q8 t' s8 }$ w
cyl1_line_coords.start_point[2] = cyl1_pt[2];
6 n3 [5 }& y9 _" g+ l; [
! t6 `7 V- c5 L+ x7 s; F; ]4 W cyl1_line_coords.end_point[0] = cyl1_pt[0];0 z$ F! b5 K. i% A1 y
cyl1_line_coords.end_point[1] = cyl1_pt[1];) z% i% T% U3 ^% I% I& [
cyl1_line_coords.end_point[2] = cyl1_pt[2] + boundingbox3[2];
$ g Z% e+ F) x3 Q3 E( {6 K& [1 _% K( j
UF_CSYS_map_point (UF_CSYS_ROOT_WCS_COORDS,cyl1_line_coords.start_point,UF_CSYS_ROOT_COORDS, cyl1_line_coords.start_point); //wcs转绝对坐标/ h9 d _/ }9 H; }9 A3 `; Y
UF_CSYS_map_point (UF_CSYS_ROOT_WCS_COORDS,cyl1_line_coords.end_point,UF_CSYS_ROOT_COORDS, cyl1_line_coords.end_point); //wcs转绝对坐标$ M3 L7 {2 R& e- |
( P0 |2 M/ }9 A! A' l; H+ |8 |
UF_CURVE_create_line(&cyl1_line_coords,&cyl_line);# W5 {9 W& x& m' U+ m$ B, }
UF_OBJ_set_color(cyl_line,186);7 V5 B f0 C2 o, @7 R
UF_OBJ_set_font(cyl_line,UF_OBJ_FONT_CENTERLINE); //设置线型2 j" W6 Q" M3 |2 D# f
" m1 _; \6 K6 i7 V- `% {2 h3 ?4 H UF_CSYS_set_wcs(user_wcs); |( Y! Y' [1 C" x
UF_CSYS_set_wcs_display(1); //显示坐标系(解决显示移动), B9 {& A4 V/ [; Z# R
% _: H4 o$ s, x: \$ X' N& ^# X goto l10;$ v; \! T7 |* `2 \+ h) A
}
5 i5 k6 q4 u5 f+ w& V4 p& |) }
4 p1 b @" u* J& y# E* u
: h# e5 Z4 w1 Y: N2 w double WCS_pt[3],center_pt[3];
3 q* t6 b& I& E- q" k tag_t xp1,xp2,yp1,yp2,c_pt,Xline,Yline;
6 P5 b0 z* f; U8 ^ UF_CURVE_line_t Xline_coords,Yline_coords;0 Z! C* O+ Y. _
UF_CSYS_map_point (UF_CSYS_ROOT_COORDS, boundingbox,UF_CSYS_ROOT_WCS_COORDS, WCS_pt); //绝对坐标转wcs
. O3 j* _6 E, L( B6 Z$ Y
- k& j/ P+ f. o& m. a. Y# V" E center_pt[0] = WCS_pt[0] + boundingbox3[0]/2;
8 q# J5 @6 E* @3 D, Z+ ^6 a1 K! R center_pt[1] = WCS_pt[1] + boundingbox3[1]/2;
5 N2 O* u2 x8 v G0 k center_pt[2] = WCS_pt[2];/ l- s: Q5 e. a
! H" W) R7 o7 f, f9 @5 O% P
* P4 i9 A: |+ i: ^+ b Xline_coords.start_point[0] = WCS_pt[0] + boundingbox3[0]/2; //X方向wcs的值+面X方向的大小1/2( K5 S/ d- L: E' D ]1 |* Y
Xline_coords.start_point[1] = WCS_pt[1];5 ~( f1 w: L, k! p2 h+ U
Xline_coords.start_point[2] = WCS_pt[2];
, ~) j" b( U3 x5 q) q UF_CSYS_map_point (UF_CSYS_ROOT_WCS_COORDS,Xline_coords.start_point,UF_CSYS_ROOT_COORDS, Xline_coords.start_point); //wcs转绝对坐标
1 K! P/ O' Z+ R; J1 N( C// UF_CURVE_create_point(Xline_coords.start_point,&xp1);
7 T( j* D- `3 o7 M. V2 \+ |" _; ^* h: N( ?
Xline_coords.end_point[0] = WCS_pt[0] + boundingbox3[0]/2; //X方向wcs的值+面X方向的大小1/2
* {3 a/ r& n5 v: J7 W Xline_coords.end_point[1] = WCS_pt[1] + boundingbox3[1]; //Y方向wcs的值+面Y方向的大小! ?- u/ K8 @4 n$ A: ]+ |
Xline_coords.end_point[2] = WCS_pt[2];( r6 V9 q$ L8 P; `9 u* K
UF_CSYS_map_point (UF_CSYS_ROOT_WCS_COORDS,Xline_coords.end_point,UF_CSYS_ROOT_COORDS, Xline_coords.end_point); //wcs转绝对坐标3 p# Z t' o* l* A
// UF_CURVE_create_point(Xline_coords.end_point,&xp2);
" y' z" ]- E; S6 v( G8 y( V' G- X! [. Y% c: w& w8 s& F7 P
Yline_coords.start_point[0] = WCS_pt[0];7 \ Y3 n) L3 d
Yline_coords.start_point[1] = WCS_pt[1] + boundingbox3[1]/2;
3 A5 U& A1 J3 t4 J; W8 R Yline_coords.start_point[2] = WCS_pt[2];
( I8 p( Z. Z( m2 P. f UF_CSYS_map_point (UF_CSYS_ROOT_WCS_COORDS,Yline_coords.start_point,UF_CSYS_ROOT_COORDS, Yline_coords.start_point); //wcs转绝对坐标
9 f" A. _, x9 t/ N; S// UF_CURVE_create_point(Yline_coords.start_point,&yp1);* x+ q6 L( S( u, Z" ~5 T
\$ M. o* ^$ E( }
Yline_coords.end_point[0] = WCS_pt[0] + boundingbox3[0]; //X方向wcs的值+面X方向的大小
! g( \4 ~, u/ g Yline_coords.end_point[1] = WCS_pt[1] + boundingbox3[1]/2;
- ~4 j& R2 W2 A# } Yline_coords.end_point[2] = WCS_pt[2];
. z" z" S! x% O UF_CSYS_map_point (UF_CSYS_ROOT_WCS_COORDS,Yline_coords.end_point,UF_CSYS_ROOT_COORDS, Yline_coords.end_point); //wcs转绝对坐标
. @7 u" Z: T7 G8 ?// UF_CURVE_create_point(Yline_coords.end_point,&yp2);
g, w' e% `( O( J/ }4 e( q' M , r5 q8 V. y) {1 Z* |" x+ r
UF_CURVE_create_line(&Xline_coords,&Xline); //创建中心线0 ?* e$ {* [- f( Q. X* a
UF_CURVE_create_line(&Yline_coords,&Yline);" N" |& ^3 E; D' ]4 F, K) B
UF_OBJ_set_color(Xline,186); //设置颜色3 ^6 z' C# h J% e' @
UF_OBJ_set_color(Yline,186);
3 |+ [- E4 G0 {& S UF_OBJ_set_font(Xline,UF_OBJ_FONT_CENTERLINE); //设置线型
+ R2 b2 y* n8 z+ K! W7 j. P UF_OBJ_set_font(Yline,UF_OBJ_FONT_CENTERLINE); //设置线型
! t1 c/ ]5 r1 I' a) ]
+ ]* c: W% U+ E- U: U& e7 X UF_CSYS_set_wcs(user_wcs);: s+ k7 \# p. l3 S/ [: R5 X
UF_CSYS_set_wcs_display(1); //显示坐标系(解决显示移动)% M/ o! C, C1 G# g
goto l10;
0 V/ o( T. c5 J: `5 N7 z9 I: Z
8 n N; b8 b2 a* K1 |( e5 m5 T}9 W% L: ^7 g X/ Y5 _( [) q
) C" u- A8 N" F+ s& O0 aextern DllExport void ufusr( char *parm, int *returnCode, int rlen )
- `, h7 L& j( M3 t) ^: G8 q{1 F2 Z' b& ~: L
/* Initialize the API environment */
; S" I$ ^6 P+ I1 v9 ?' y if( UF_initialize() )
`+ Y0 @1 t! `! n- Q {, E) c# ^( R4 @5 b; S$ v
return;
/ K# L @6 k+ G( f7 f) Q }" j5 z1 s" c7 Z# T# R5 T2 @: {; d
0 t# R! ~$ Y$ l) r# Z1 V
Create_Center();# D' O( H) E+ E7 X9 G( r3 U+ g
9 B. _/ K" B0 W" h UF_terminate();8 E# o9 X% ^+ f M3 y
}
' e; h$ i) Y9 x4 P* Y! x3 w Z' w+ o
S% n* E7 [- h! |$ Q# @2 |extern int ufusr_ask_unload( void )
# d) U3 X1 E# V+ {& w' a{) ^" }& Z) e$ z, K# o0 c
return( UF_UNLOAD_IMMEDIATELY );
: u0 N$ M3 O9 U, R3 o# J2 Q}
3 L% D' N* k6 @/ I7 o4 u) r) }
: F, a7 `" `! ^( d4 `7 @! b( y+ P7 _" z; F% \
2 Z( S! I u- G' L# z5 J
% Z) R. u V$ k& b3 Y |
-
|