|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线8 k- i9 L7 p8 C+ N. o
- #include <uf_defs.h>8 ~, @7 `/ ?/ y" V" ~" x
- #include <uf.h>' S4 q, q! P5 Y
- #include <uf_modl.h>
. Q* R. e. u1 o( d, D, |" h8 U# b - #include <uf_object_types.h>& _$ I' ~0 ^& Q5 T& O9 t8 j
- #include <uf_ui.h>
- D2 M% X; |& p* x$ E - #include <uf_modl.h>
8 E; ]( X' E F9 I3 A' _1 B9 a - #include <NXOpen/NXException.hxx>/ M* s$ O! X" _) o" V* _5 D+ R
- #include <NXOpen/Session.hxx>* v; ~1 u: |5 k4 Z8 z% m1 f+ E% E
- #include <NXOpen/Selection.hxx>& p, I, B c. Q0 { T! h9 w0 Y
- #include <NXOpen/Builder.hxx>% Q( Q7 W: y- S+ `" O
- #include <NXOpen/Features_Feature.hxx>7 z( K5 I" o# v4 Y* ~8 U" w
- #include <NXOpen/Features_FeatureBuilder.hxx>; ^6 ?* T0 t, X# T
- #include <NXOpen/Features_FeatureCollection.hxx>( c* g0 `5 I2 A: ~9 {
- #include <NXOpen/Features_GeometricConstraintData.hxx>
; ?7 n0 [/ B0 w, W% s% z - #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
# A; ?; t3 A y& g* f' H - #include <NXOpen/Features_StudioSplineBuilder.hxx>, W; c" E5 q0 \# T2 z9 G' `# l7 T* I
- #include <NXOpen/Part.hxx>
! B7 _' Z, M9 I: i) y - #include <NXOpen/ParTCollection.hxx>/ f0 H8 z0 t- y
- #include <NXOpen/Point.hxx>
+ k. ]; H5 e, p% f1 n& o2 P - #include <NXOpen/PointCollection.hxx>
* X& Z0 L( u% `4 L. |, e - #include <NXOpen/NXString.hxx>
6 F$ K% t5 r) ] c, j2 q3 J - #include <NXOpen/UI.hxx>$ J) X9 L/ n) P; [5 V3 u
- #include <NXOpen/Spline.hxx># Q" u/ l% S+ C: O4 `5 f
- #include <NXOpen/NXObjectManager.hxx>
- y1 l# f0 T6 b( V. d
% E& l2 O" q% }6 R* D* o3 r, \- using namespace NXOpen;
: L1 g- _! z( X9 P9 X6 Q2 F) C N) b - using namespace std;; o6 I# @* @9 [$ b! j' r' Q' ?) }! i
- 9 Q9 n2 U0 H! a9 G( a. p- u
- extern "C" DllExport int ufusr_ask_unload()2 b' ^' \# s& d+ f8 G
- {8 G, q8 k& X3 r0 C/ b
- return (int)Session::LibraryUnloadOptionImmediately;3 Q* a9 V+ i/ c7 W/ s, w" b- U
- }9 ~' G- u4 ^+ ^* F- V
- 9 N" v2 o1 s; i$ ^/ _
- static vector<Point *> selectPoints(NXString prompt)0 r) O8 B' Y. g; F) L! A
- {
. [2 b/ p" A# `2 M6 F - UI *ui = UI::GetUI();2 M4 G8 o- z6 D- n9 U$ F8 ^
- Selection *sm = ui->SelectionManager();6 i$ Q8 {( ^9 M8 t- \4 l# t* F7 r# U8 [$ [
- std::vector<Selection::MaskTriple> mask(1);
% e. L3 m. v) `# ]5 S1 S: C. | - mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
! J4 H1 E; z% M$ S w, A - std::vector<NXObject *> objects;, w8 d1 b+ q. a6 M' X) V: y
) @! N) Y. s: X x V) d- sm->SelectObjects("Select Points", prompt,7 n, _+ I, n+ @+ e' x
- Selection::SelectionScopeAnyInAssembly,' F! O# j# S l; V) e3 a
- Selection::SelectionActionClearAndEnableSpecific,6 t" G, H1 L" E* g( x! O
- false, false, mask, objects);( @* q( e! I) o1 t0 [( @
" Y7 M5 s! e. _( l8 B. J! p( ~- vector<Point *>selPoints(objects.size());( H- T* F k; [4 Z3 ~+ F
- for (unsigned int ii = 0; ii < objects.size(); ii++)
1 B& V; T9 W0 f# T/ c* J - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
1 I; \, P [0 e2 S9 T8 y* ? - 6 V2 ~4 n7 F2 Y+ u
- return selPoints;* Q+ _2 T' ~- b: y- w9 }$ z/ K8 u
- }/ A; S4 y$ D$ a. _) U7 T+ y% T8 M) Z
- $ |$ ~, H6 W$ F, S3 T
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
, L6 [5 o9 L. O! @1 P( p9 M( B% x - {% b0 e- L6 i& M, L6 f: f" g) o5 i' f
- Session *theSession = Session::GetSession();' b4 l7 P* J# ^( O
- Part *workPart(theSession->Parts()->Work());, w+ ]& A) y0 ~: I
- : m A9 K# S" x, b# ?
- Session::UndoMarkId markId1;
) Y- q2 }! V- t' ?3 ]! ]; A - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,* ]2 Z: H6 `* H+ s
- "Studio Spline Thru Points");
( \7 ]7 L' }( R ?) y3 \2 b
' \" C* |4 g$ c) P- Features::StudioSpline *nullFeatures_StudioSpline(NULL);, p/ Q. _; m9 y2 I
& p# [. v. I. l1 @8 N4 m- Features::StudioSplineBuilder *studioSplineBuilder1;
, S9 m6 [! o D6 K; f+ H9 u - studioSplineBuilder1 = workPart->Features()->
! [& X% ~! a4 H% Y5 I5 U) q) G0 V - CreateStudioSplineBuilder(nullFeatures_StudioSpline);3 D. d+ q: n3 ]- t+ _
- studioSplineBuilder1->SetAssociative(true);
* W" m3 y7 Q! f' @; Y0 r! }. M - studioSplineBuilder1->
# X. j9 h9 @4 N& i - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
; b, G5 I* X/ ^3 j% U - studioSplineBuilder1->6 W( K& @. N8 `, g$ f
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
/ @6 q4 |+ P: `) M+ K - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);0 Y; J4 c6 S: j; A( ?- ~. a @1 n) \
- studioSplineBuilder1->SetPeriodic(false);
/ ~3 d; I3 ^" o9 ?8 l7 B - studioSplineBuilder1->! f. ~- X% P, ^ f8 u+ C5 M8 M
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
! J$ t0 t0 K/ ]* y1 z1 A1 {& F( X - std::vector<double> knots1(0);
# k/ n& Z0 G8 ?6 c/ ~% A - studioSplineBuilder1->SetKnots(knots1);
" X: _- D, \. g4 b - std::vector<double> parameters1(0);
4 |6 z0 R3 B8 R% L# R - studioSplineBuilder1->SetParameters(parameters1);
5 [! J j* q: N0 N8 i - Direction *nullDirection(NULL);7 G8 d- C. D5 P$ k; z/ v, i3 x4 M
- Scalar *nullScalar(NULL); J! v# @2 c6 @4 P
- Offset *nullOffset(NULL);
& J3 z. k* T. y" `0 o - 1 H0 ~5 T% a: [: {. V) }4 E) E0 L& k
- std::vector<Features::GeometricConstraintData *>+ d$ p6 ~9 _3 a/ c3 x, J" U( e8 b
- geometricConstraintData(thePoints.size());0 e' a! v5 X* G* d2 ]
- , o5 q0 Q" C+ d+ W
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
- [! P+ `- J! a - {
2 C: g# P& e* g" e% J - geometricConstraintData[ii] = studioSplineBuilder1->
+ v* ^) q; g, A- O4 \4 v' l - ConstraintManager()->CreateGeometricConstraintData();
/ Z, x5 o7 l& F0 Q, a - geometricConstraintData[ii]->SetPoint(thePoints[ii]);
2 L/ M5 C% n$ g7 G6 m0 f$ ~* v - geometricConstraintData[ii]->SetAutomaticConstraintDirection(
5 P2 ^% y% c1 [0 P4 Y: q5 D - Features::GeometricConstraintData::ParameterDirectionIso);) ]; b. b* |, X. r4 F: k$ x9 z/ f7 R
- geometricConstraintData[ii]->SetAutomaticConstraintType(
9 c9 u8 }+ \; {2 T1 y( X( L- K - Features::GeometricConstraintData::AutoConstraintTypeNone);
2 G! ?3 }6 }. E8 d* k1 L, P - geometricConstraintData[ii]->SetTangentDirection(nullDirection);
! r2 n3 X" u; u0 \( W) n; Z - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
, ]4 w" m' X; o8 Q - geometricConstraintData[ii]->SetCurvature(nullOffset);
$ p* D5 a |# S; ]& p* [: y3 Q - geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);' Y5 {; y- K8 q, D' S' ]) J
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
1 b5 y1 O8 d" Q9 r! f7 p' u4 ]8 g - }. I% h& a$ C8 ^, p, Q
- ; _0 Q z! e8 M" ]' G* X2 V
- studioSplineBuilder1->ConstraintManager()->SetContents(
- U$ U* B( r2 Y) E/ ? - geometricConstraintData);
8 |6 J! L) E& @6 r/ |- g5 R, _ - ( k9 R) Q) O& E5 E' N; w
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
0 d0 _( i+ q+ p; Y1 q% h- Q - Spline *theSpline = studioSplineBuilder1->Curve();
F6 g) f6 L2 \6 G. z. u4 o
; @2 d( S' }' _/ @- studioSplineBuilder1->Destroy();
: y8 |* R8 v* O* d* R - ! ^: o% c& C- h1 X4 [% t- O6 x/ V
- return theSpline;
( f! S5 o0 p2 Z# P$ k6 j' m - }5 B$ |& Z L6 d$ K
- 0 ^9 H, K Y2 s5 v( |& w
- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
1 A1 w$ M0 d# u+ t - {
' F2 @1 K. B9 @) C' T2 o - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
2 f! Y; h3 A+ T- V# b - if (!thePoints.size()) return;2 m* k* E* g, U' x: V* {' s
! B" r" M; ^) c7 O" a" k4 U" q- Spline *theSpline = createStudioSplineThruPoints(thePoints);
- i# j8 P) V8 j5 A
`5 \$ X+ g+ {" p1 p' _) H- if (theSpline)
/ R# ^, Y7 o6 `& c n% U - {+ c4 P8 w6 g/ F
- theSpline->Highlight();
/ g; w5 T: ]8 |5 c k - uc1601("Studio Spline Created Thru Points", TRUE);
9 I5 q6 N+ B" s5 O - theSpline->Unhighlight();
& t" o4 Q. I+ J2 H - }
4 g$ W) r0 z# B, F - }
1 n0 r$ P) J; c$ Y3 X3 `+ @: O
复制代码 4 o; m% O6 s ?" @
; J2 Q" J, J5 c5 r z& A; A/ {
5 z8 t. h- [, J; d0 S: I$ W
|
|