|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有帐号?注册
x
: c3 e5 M9 z( c6 i. g$ {, C#include <uf.h>& b c% x9 _/ i- }
#include <uf_ui.h>
9 s/ ~+ M6 Z2 Y8 e6 x" h#include <uf_exit.h>3 B! k: D0 d8 n* P2 Y! f8 v2 f
8 S6 ~6 l1 `1 {* _. m
#include <stdio.h>7 h+ R$ g3 e, d) k- v) [
#include <uf.h>
" m5 P( }% t5 U#include <uf_ui.h>
$ a: S8 L- d/ {5 `% t#include <uf_exit.h>
& G- w5 \% ^3 w' f2 y* v#include "uf_layer.h"& p6 l' y, j" D) {6 K' c- }# \7 ?
#include <stdio.h> D) j7 M5 T6 r' Y% g6 e
#include <uf.h> a( q2 [' m: m. J
#include <uf_modl.h> [0 ?4 _6 u8 B8 E: A3 Q: }9 s
#include <uf_curve.h>) G2 T9 R% d/ D3 E( X
#include <uf_csys.h>- l; `$ E; d+ P% @
#include <uf_object_types.h>
& _$ {6 m. N! S% k4 h. r#include <uf_ui.h>8 n: F& U) s8 [) O6 A# P
#include <uf_part.h>- ^% n3 f0 G0 k( ]/ }* r n/ E
#include "uf_obj.h"
2 C T; Q( ^' E#include "math.h"
- k/ Y2 t# `8 M. _: Y+ x4 E. w: o
- v9 s2 e* K& Q5 P7 s; v2 Kstatic int init_proc(UF_UI_selection_p_t select,void* user_data)1 l5 v, P+ g2 N
{
9 q/ @* Y& ~6 V) t int num_triples = 2; //只选择一种类型
* n, Z1 {& N* k- i. B UF_UI_mask_t mask_triples[] = {UF_cylinder_subtype,0,0,$ {& R8 U, E0 L& q a
UF_bounded_plane_subtype,1,0};* b% j) I5 Z8 u9 O* {- k
if((UF_UI_set_sel_mask(select,0 b; g+ S9 @8 a
UF_UI_SEL_MASK_CLEAR_AND_ENABLE_SPECIFIC,: N) x0 o/ R. G& s- b, F7 K* v" B; p
num_triples, mask_triples)) == 0)
9 d6 x: V* x% w- q& b# ?8 ]' P {
3 _$ M& }* ?! u3 G0 d+ a; a return (UF_UI_SEL_SUCCESS); B/ L% z+ N. w7 P2 _5 ^3 ?
}
# m5 A2 |2 o$ \1 u9 V1 a& ~ else- u& ]0 q2 i" t+ B+ K3 v2 {. C- g
{( k. d' u6 g. f* a. `; s# l: |
return (UF_UI_SEL_FAILURE);2 X8 O! x _. ]0 i+ }
}: h' v/ P" g" f, k* E' H2 [4 K; Z
}
) B/ R0 P: a t( |& H' g
! e0 ]8 y1 G. f6 t$ k
3 h7 }7 Z1 j0 b! f8 q4 G& ?static void Create_Center(void)3 q( F2 G1 U! p% E8 D' c
{
/ s s9 j3 o" Q" o, R tag_t user_wcs;/ m2 L+ m9 U9 ~
UF_CSYS_ask_wcs(&user_wcs);
6 C2 u2 K9 @2 T9 z7 V2 W char cue[] = "简简单单:请选择单个平面";
0 p+ x( |, N, h, r char title[] = "简简单单:对象选择对话框";! Q$ F; c/ y1 c# _% Y
int response=0;
+ S- u3 Z7 e3 s( { tag_t object;. g# p2 W& z. V7 a+ W3 F/ z" u$ I
int count=0;8 R1 e' V- V. u5 p. G+ k
double cursor[3];
7 U; r4 @3 ~- w8 J tag_t view;
: s% k& u, j% p: @! @) {2 zl10:
N4 S0 N/ B1 S1 x1 c UF_UI_select_with_single_dialog(cue,title,0,init_proc, NULL,&response,&object,cursor,&view);
3 t- I; z' N# }0 I, V C9 O if(response==UF_UI_BACK) return; //如果点后退就跳转到L10
, d! }: j; [! l if(response==UF_UI_CANCEL) return; //如果点取消就退出) C9 M' Z3 [: r/ J$ ^
UF_DISP_set_highlight(object,0); //取消高亮显示
7 j: \: P& | s& t- H# l4 s1 b2 A: S0 q$ j' b
int type;- t' ?; G* H. ?- D8 X: e
double point[3],dir_z[3], box[6];
9 S' [* ]$ O8 u2 K; ~ double radius,rad_data;
, k/ f8 e8 V2 B; w int norm_dir;
* r/ I- x! \* C: j5 y UF_MODL_ask_face_data (object,&type,point,dir_z,box,&radius,&rad_data,&norm_dir); //得到面的法向norm_dir,+1为正向,-1为负向- j. M" z( \5 B X; o; D# J
. g3 @( E3 i) L
! x; x" }3 @+ z9 p: S/ a- n {- i tag_t matrix_id;+ D# L. A* r2 n% r4 X
tag_t csys_id;' y. b5 { {( i+ l4 l' R
double matrix_values[9];
0 N! Z$ x! R2 [7 a5 _ UF_CSYS_ask_matrix_of_object (object,&matrix_id); //得到面的矩阵ID
' z) ?' m' X# c# o- G' @" Z! T- e UF_CSYS_ask_matrix_values(matrix_id,matrix_values); //赋值给matrix_values" [/ W' _; ?! w$ W# I+ d+ B
if(norm_dir<0) //判断面的法向是否相反9 x% |, y0 S, T# G" U
{
9 I0 p+ L/ M! ]( s9 C matrix_values[3]=-matrix_values[3];; w6 s, a5 N( ]5 z' v
matrix_values[4]=-matrix_values[4];9 G" T3 C5 T+ s3 {1 Q
matrix_values[5]=-matrix_values[5];
( v* |/ l7 h( w1 i5 V matrix_values[6]=-matrix_values[6];/ q4 p- G' B9 k0 G3 k" C
matrix_values[7]=-matrix_values[7];. ^' {9 I8 k1 E6 D0 }
matrix_values[8]=-matrix_values[8];
D/ O8 S, r r: G( }/ O UF_CSYS_create_matrix(matrix_values,&matrix_id);
M( R; X+ ?# T# u- J n }0 P! c d' @3 |& P2 J: V
UF_CSYS_create_temp_csys(point,matrix_id,&csys_id);0 M8 Z" X5 J+ t4 _: t, _* z
UF_CSYS_set_wcs(csys_id); //设置面的坐标系(位置不一定精确,可以通过后面修正)- N7 [& O% F) G# J8 l- \; B/ J
UF_CSYS_set_wcs_display(0); //不显示坐标系(解决显示移动), |3 P6 H" a; B7 {7 j: s; Q$ u
+ b* x& ~) g8 k# W7 @7 b7 \: R double boundingbox[6];
& u+ t( A, d& Y; w! x7 n4 ` double boundingbox2[3][3];
# C7 H: k6 E+ M double boundingbox3[6];
' e5 a- k2 Q4 ^" s6 q& [1 }) ? UF_MODL_ask_bounding_box_exact(object,csys_id,boundingbox,boundingbox2,boundingbox3);
3 r- w( e+ R1 j$ S( U
2 d; e ^* q8 V if(type ==UF_cylinder_subtype)/ G! k' t* q9 m( l
{3 `- o) l: L4 Y) l0 ]
double cyl1_pt[3];5 m: C D- a% i" _; ^' S
tag_t cyl_line,cyl_pt;% X: H, r: s7 K `1 i0 G
UF_CURVE_line_t cyl1_line_coords;9 \1 w1 ~$ v( F6 [2 a
double WCS_pt[3];. X, V% z& b% [( W' Z. c2 S0 o4 L
UF_CSYS_map_point (UF_CSYS_ROOT_COORDS, boundingbox,UF_CSYS_ROOT_WCS_COORDS, WCS_pt); //绝对坐标转wcs
' ?- j1 t9 F( T3 m0 m$ { UF_CSYS_map_point (UF_CSYS_ROOT_COORDS,point,UF_CSYS_ROOT_WCS_COORDS, cyl1_pt); //绝对坐标转wcs
& o' L) z5 V! V5 _/ J cyl1_pt[2] = WCS_pt[2];
- L, c$ ~0 E9 j& d! a7 a3 W) e2 l" s% O/ G5 r
cyl1_line_coords.start_point[0] = cyl1_pt[0];" E4 P# P% S5 G
cyl1_line_coords.start_point[1] = cyl1_pt[1];
b% r$ x4 w: D/ J# {/ r8 F5 O cyl1_line_coords.start_point[2] = cyl1_pt[2];) X+ M. Z/ _4 l. l# W" @
$ F# C6 d5 t7 l
cyl1_line_coords.end_point[0] = cyl1_pt[0];! \, q9 i8 {/ e* T7 t
cyl1_line_coords.end_point[1] = cyl1_pt[1];9 h5 V& x# U0 w8 s2 }. Z9 ` R9 p
cyl1_line_coords.end_point[2] = cyl1_pt[2] + boundingbox3[2];
7 G9 P6 y U* G7 J2 w5 R$ Q+ H" s" C; ~: H
UF_CSYS_map_point (UF_CSYS_ROOT_WCS_COORDS,cyl1_line_coords.start_point,UF_CSYS_ROOT_COORDS, cyl1_line_coords.start_point); //wcs转绝对坐标
. C n3 {( j9 t6 K UF_CSYS_map_point (UF_CSYS_ROOT_WCS_COORDS,cyl1_line_coords.end_point,UF_CSYS_ROOT_COORDS, cyl1_line_coords.end_point); //wcs转绝对坐标
* y5 W* [; N0 ?1 y. h
. ]. | {* j, r* } UF_CURVE_create_line(&cyl1_line_coords,&cyl_line);
; |1 B( p. ~6 d, [" Q UF_OBJ_set_color(cyl_line,186);
$ N/ W# L$ d$ X8 g9 ~3 q UF_OBJ_set_font(cyl_line,UF_OBJ_FONT_CENTERLINE); //设置线型( u! X* ` ?/ C: w* V; x8 p6 o
7 t% t$ J$ z8 B' B! `( Q UF_CSYS_set_wcs(user_wcs);
$ C7 A& ^' Q8 I UF_CSYS_set_wcs_display(1); //显示坐标系(解决显示移动)# d& p& T4 ]$ i8 F/ _
* U! |0 [6 ^" ?( H6 P
goto l10;# \# s5 A* b% y/ k
}
, u$ B' ~- S+ ]9 M5 E
q v4 ^9 p. f! _: H- `
; c3 A# Y2 L& N5 W* [. c% G& R double WCS_pt[3],center_pt[3];- j' t. G" C3 P2 M: Q: f7 T/ V
tag_t xp1,xp2,yp1,yp2,c_pt,Xline,Yline;
# P! m- r( K% s" o" k UF_CURVE_line_t Xline_coords,Yline_coords;
; C6 y# w% d" W7 m) {6 h UF_CSYS_map_point (UF_CSYS_ROOT_COORDS, boundingbox,UF_CSYS_ROOT_WCS_COORDS, WCS_pt); //绝对坐标转wcs
9 {. d3 Q8 D1 o7 J3 a
5 G. E( d1 Z% ~ center_pt[0] = WCS_pt[0] + boundingbox3[0]/2;
: b" C9 n: q3 l" M center_pt[1] = WCS_pt[1] + boundingbox3[1]/2;1 [& J+ ^+ J" Y) f3 ^( r' y" @ c' {
center_pt[2] = WCS_pt[2];! U0 ` S1 V# l9 i/ D8 f
+ e& c( B' C9 o. L) z
- J+ l! M* l/ S3 I! D C7 ^0 N9 I, y
Xline_coords.start_point[0] = WCS_pt[0] + boundingbox3[0]/2; //X方向wcs的值+面X方向的大小1/2
/ Q3 k/ T& k) [& z2 _7 M+ u8 G Xline_coords.start_point[1] = WCS_pt[1];
; k+ H* V% G9 b& a- \ Xline_coords.start_point[2] = WCS_pt[2];
" R# E& {0 l9 N0 D) ~7 m6 u! t UF_CSYS_map_point (UF_CSYS_ROOT_WCS_COORDS,Xline_coords.start_point,UF_CSYS_ROOT_COORDS, Xline_coords.start_point); //wcs转绝对坐标8 {( q8 e, `5 t- k1 x* o I
// UF_CURVE_create_point(Xline_coords.start_point,&xp1);
, p. k, {) d# @
# d- c7 B* ]" l- I# o4 { Xline_coords.end_point[0] = WCS_pt[0] + boundingbox3[0]/2; //X方向wcs的值+面X方向的大小1/2
2 X1 ?3 g( V! {& |2 T& B Xline_coords.end_point[1] = WCS_pt[1] + boundingbox3[1]; //Y方向wcs的值+面Y方向的大小% T$ J9 y5 [# u/ g! A8 x; Z
Xline_coords.end_point[2] = WCS_pt[2];6 v* X& Z$ z! |& l
UF_CSYS_map_point (UF_CSYS_ROOT_WCS_COORDS,Xline_coords.end_point,UF_CSYS_ROOT_COORDS, Xline_coords.end_point); //wcs转绝对坐标) D' D$ J9 x. g# T
// UF_CURVE_create_point(Xline_coords.end_point,&xp2);4 K0 p. Y( f6 Y& ?1 w1 Q3 ~4 o
5 ~$ m% t' _( a$ ^( g$ H* d/ J; D Yline_coords.start_point[0] = WCS_pt[0];
/ u# v& n- Z4 y/ d0 i6 r Yline_coords.start_point[1] = WCS_pt[1] + boundingbox3[1]/2;) K. s m# _, h: Z; T, o, w' U
Yline_coords.start_point[2] = WCS_pt[2];
! R) y4 b$ R- B- A5 c UF_CSYS_map_point (UF_CSYS_ROOT_WCS_COORDS,Yline_coords.start_point,UF_CSYS_ROOT_COORDS, Yline_coords.start_point); //wcs转绝对坐标* G$ M$ U+ f; S5 c
// UF_CURVE_create_point(Yline_coords.start_point,&yp1);) U8 N P! w: O! q
- ]* T2 ?2 i8 O. P0 q& a( F, g Yline_coords.end_point[0] = WCS_pt[0] + boundingbox3[0]; //X方向wcs的值+面X方向的大小
7 s* P( m8 [# K* d% r" N9 `1 I3 X n Yline_coords.end_point[1] = WCS_pt[1] + boundingbox3[1]/2;$ S6 f' c6 k; H! N4 ?' }: g
Yline_coords.end_point[2] = WCS_pt[2];
: ?; j, x; D3 ]3 ]/ _7 W6 g1 f UF_CSYS_map_point (UF_CSYS_ROOT_WCS_COORDS,Yline_coords.end_point,UF_CSYS_ROOT_COORDS, Yline_coords.end_point); //wcs转绝对坐标
3 f& R9 A5 V% _// UF_CURVE_create_point(Yline_coords.end_point,&yp2);
5 ?& K* \7 ?1 a' ~# T $ v- a, e1 l \2 w( `! l8 q$ x2 U
UF_CURVE_create_line(&Xline_coords,&Xline); //创建中心线7 V& g. V8 l0 M9 l) ?9 k
UF_CURVE_create_line(&Yline_coords,&Yline);& |; f {( k3 ~$ _. [ p
UF_OBJ_set_color(Xline,186); //设置颜色- a- d O( E( o- B1 I& e$ H
UF_OBJ_set_color(Yline,186);2 H2 X% K) P+ R2 e7 d8 u5 `
UF_OBJ_set_font(Xline,UF_OBJ_FONT_CENTERLINE); //设置线型) S+ {* m6 u; |0 P* {
UF_OBJ_set_font(Yline,UF_OBJ_FONT_CENTERLINE); //设置线型! o5 m+ b7 r. g6 Q, x. h
6 \# R% ^& u0 e2 _, `) v UF_CSYS_set_wcs(user_wcs);
8 T4 s4 i; B- f& `5 d' \ UF_CSYS_set_wcs_display(1); //显示坐标系(解决显示移动)! l$ ^* U7 F& R# A& \
goto l10;
& q' J6 U# M! K: o/ k6 u* j
' o4 H/ t6 s% u0 b}8 R7 d1 g1 U" l) |3 }( v- J
4 ?+ F" e0 }" n# dextern DllExport void ufusr( char *parm, int *returnCode, int rlen )+ T& @6 j0 A' w* f! h5 J
{; v/ {; f8 O7 @& w' J
/* Initialize the API environment */
% S# ^2 ~" @& _* P" g if( UF_initialize() )
0 A( M8 Y1 D5 O8 Z+ S9 n4 O2 e8 X {; G# h: c) ]# ]( o, C
return;) S* M+ N3 w& V Z4 b
}
( Z3 _; G+ C6 r' L0 z& C" e9 L6 r/ W9 [6 \
Create_Center();# T9 [) o/ s2 J+ ~/ N
7 [8 ^* h: H6 s- M' N/ I UF_terminate();: l$ i* g6 n+ K0 F! e: u, ^: \
}
( |+ S9 p/ d( C) D& y
2 U2 ]* z( k- l- s* v* ^
( d8 |$ M. z v1 D9 Yextern int ufusr_ask_unload( void )
' y, k, ~8 t% f{
, V. G/ u# p5 A1 S, ]0 _2 z return( UF_UNLOAD_IMMEDIATELY );1 W0 l1 g5 a' J1 R } p- M* Z. R
}
" l2 W$ O9 N8 k- i% R2 R' a0 p X7 O5 c2 i
, M {$ w8 f: f& b u% j4 N2 w1 O
; G; ~" L" H; y% {& ^4 n. G |
-
|