|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线
. f. e' H Z* _- #include <uf_defs.h>
3 S& L) j. m, W1 @ - #include <uf.h>
0 j. F. u8 E2 U* c! F, ? - #include <uf_modl.h>0 O8 D: F! A! \% u* k# _+ F
- #include <uf_object_types.h>
5 Z1 w& N* U, } t( d/ T; A - #include <uf_ui.h>
3 M9 O9 Y& _/ Y- ^ - #include <uf_modl.h>
% a3 O! |; `1 M: ~ - #include <NXOpen/NXException.hxx>
3 B! R f$ E9 S' }* B; Z - #include <NXOpen/Session.hxx>
5 g; x; I$ U& y- V$ |8 E - #include <NXOpen/Selection.hxx>: Q2 W/ L" l( B' l% E1 o
- #include <NXOpen/Builder.hxx>
% h7 s' `6 {% z' {! c1 I - #include <NXOpen/Features_Feature.hxx>
0 x+ H+ m9 p+ Y: J5 p2 V3 g! K/ |6 W. O) Z - #include <NXOpen/Features_FeatureBuilder.hxx>+ \& _0 b$ c$ T: @% Y2 c/ l X
- #include <NXOpen/Features_FeatureCollection.hxx>8 _/ B* K" P+ j; A/ T3 P
- #include <NXOpen/Features_GeometricConstraintData.hxx>
4 s5 Q9 ^3 }" ^% c) k - #include <NXOpen/Features_GeometricConstraintDataManager.hxx># ~0 g( Y9 C" I( p+ J
- #include <NXOpen/Features_StudioSplineBuilder.hxx>
: R8 C* r4 e4 ~1 f: |( m - #include <NXOpen/Part.hxx>3 A. {5 `' y2 K1 `& d+ q' U& G
- #include <NXOpen/ParTCollection.hxx>
5 |. F" y# Q8 z i9 D - #include <NXOpen/Point.hxx>7 `- r- P# h* q2 v6 y
- #include <NXOpen/PointCollection.hxx>
1 k) Q) M N W1 L0 u5 S$ h - #include <NXOpen/NXString.hxx>
K0 y- O: i. P8 e ] - #include <NXOpen/UI.hxx>% Z* K4 Y1 A( s( \8 Q
- #include <NXOpen/Spline.hxx>
8 r1 S ] V' t, Q0 I, Z; _ - #include <NXOpen/NXObjectManager.hxx>
/ E2 @0 t" Q p4 B8 ^ - % k4 v2 d4 d5 I6 T, t0 l1 h
- using namespace NXOpen;
, i: w' c7 `" q. R) Q0 O( ]( A - using namespace std;
, v* ~. e5 U1 m$ n% l" y/ N - # M, {! e& W. M7 s
- extern "C" DllExport int ufusr_ask_unload()4 G; z+ [7 [! K5 a" P
- {& u! q; q0 ~- {* T7 F
- return (int)Session::LibraryUnloadOptionImmediately;
: }+ r* i Q' G: e. R - }# S; k# f' I# @+ M( C: ~
- $ r% N) @/ V" _) @& Y( }6 G7 c
- static vector<Point *> selectPoints(NXString prompt)+ B6 g( }9 {1 z" z' Y G4 \
- {
6 Y6 z3 Y; K2 m( o - UI *ui = UI::GetUI();& E+ e$ s o" I% @: j
- Selection *sm = ui->SelectionManager();) b) e/ Y3 C4 a. y6 u
- std::vector<Selection::MaskTriple> mask(1);
0 ?5 h i3 J; ]' R2 R$ e8 q - mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
6 z, H. m) `# Y9 ^3 ] - std::vector<NXObject *> objects;
3 F# [/ Z! v: C! b- g8 N
5 W" ^ @) ~% C& o' j9 r- sm->SelectObjects("Select Points", prompt,
& _ Q% J, c) E: y - Selection::SelectionScopeAnyInAssembly,
; }' Y# [! E I4 W' x2 H% F - Selection::SelectionActionClearAndEnableSpecific,: l& B% ?7 X2 T+ f5 z; \
- false, false, mask, objects);
( ?# F5 W2 ` r+ |) p) ]: Q
# C& o' ^; s7 O: w- vector<Point *>selPoints(objects.size());
2 C4 N; X7 B0 x) |2 a% A' K - for (unsigned int ii = 0; ii < objects.size(); ii++) p5 W, [2 t( z+ _8 |
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);5 T9 I' j% A0 u) t) l+ r# |
6 f: W% R/ S( r7 D U- return selPoints;
1 Y' P, t: V+ B' V: k `# n! I - }
/ A: X" \' L; T- o
; N9 N% E# @+ q: D- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)0 d: _1 w: z1 j4 @+ N" ~
- {
, M' Q( ^6 C9 Z6 }) C' B7 y - Session *theSession = Session::GetSession();
/ G: W) y, O$ A* }2 z/ z2 a - Part *workPart(theSession->Parts()->Work());# A: Z$ ]( s3 G, q2 M
- * o3 [6 Z' A$ X! r6 r
- Session::UndoMarkId markId1;) U# I( [/ g( m! {
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
8 J8 ^9 {: t& Q' S; v - "Studio Spline Thru Points");
1 ?3 `/ I, G: y+ t1 Z# @ - 5 D3 X2 Y9 v# I& u1 _, \* F
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);" P5 S# j/ Z# p: Y9 @4 v
- . i( _( x1 T, }0 D0 v7 O# q0 ]
- Features::StudioSplineBuilder *studioSplineBuilder1;
t. d' t( i5 ~% Q - studioSplineBuilder1 = workPart->Features()->7 X" t& d( h& |3 m; X
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);
) N8 @0 r8 Y! S/ o - studioSplineBuilder1->SetAssociative(true);0 i1 O! l) L0 Q6 Y
- studioSplineBuilder1->
, U. V4 a5 ~& z9 I5 f j - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);" o g+ `, F, I8 l
- studioSplineBuilder1->
# e2 M; K+ c3 p7 l2 F- [ - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);/ f) P& t; z% o3 {2 [7 r' ]2 \. {
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
0 ~/ z. V* x3 S! {. w+ M - studioSplineBuilder1->SetPeriodic(false);0 a2 u1 q8 p* q/ c
- studioSplineBuilder1->
: r, T( p0 j$ _2 K( O! g: z3 W - SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
: U) b2 r; v8 Y* d3 e4 A2 ] - std::vector<double> knots1(0);
# g) T; a% u/ _9 O: H3 h - studioSplineBuilder1->SetKnots(knots1);0 c2 \. d# R1 T; h
- std::vector<double> parameters1(0);
! a$ X6 K( P+ K6 z4 L - studioSplineBuilder1->SetParameters(parameters1);4 v- K) ~& q* A1 [, T& g% p
- Direction *nullDirection(NULL);
v" b' A$ i0 |( J* o- m - Scalar *nullScalar(NULL);
6 i6 b, l! o: q1 o - Offset *nullOffset(NULL);7 j+ _! }; E) o0 }. W; Q& {
- / I1 O7 y" h: r
- std::vector<Features::GeometricConstraintData *>
4 w7 ~9 @8 u3 W) [& t - geometricConstraintData(thePoints.size());7 y$ g$ i" z7 w& |% Q* D8 H
, Z3 q* _; f) s+ J! r- for (unsigned int ii = 0; ii < thePoints.size(); ii++)9 z# V, F& R' O4 \% A% G. w6 n
- {) T/ w0 _3 E% }
- geometricConstraintData[ii] = studioSplineBuilder1->9 W y. O# I1 W4 A9 p: B
- ConstraintManager()->CreateGeometricConstraintData();; B. x# J! r2 y) M8 s
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);4 E% d8 m( W, f
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(
4 _! u4 \) k3 `8 c i - Features::GeometricConstraintData::ParameterDirectionIso);, B" _+ P7 J5 N Q
- geometricConstraintData[ii]->SetAutomaticConstraintType(% n9 p5 A: i% v; j) W3 [
- Features::GeometricConstraintData::AutoConstraintTypeNone);) G& L1 M( ^4 v8 A1 x
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);
" _8 N* d- `& B9 q2 |! T - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);. ]5 c5 O0 F) f! H; n* q$ B
- geometricConstraintData[ii]->SetCurvature(nullOffset);
9 A3 z/ _! X9 U: T: K; B1 p- V. M% k - geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);" L, q) [4 {' n5 b! L+ E0 G# p
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
& r4 X$ s7 S- v2 {+ H - }/ n. ^. ]/ W9 [
- # L3 N/ n) [! Q @
- studioSplineBuilder1->ConstraintManager()->SetContents(9 p. x! R0 |+ e$ K7 o
- geometricConstraintData);3 h2 U) ^$ R8 x% B# a9 y
8 |5 F8 f" e4 H# u8 {; |4 {- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
+ B5 B A1 ?9 a+ n% w - Spline *theSpline = studioSplineBuilder1->Curve();
) a% C; \! Z0 X5 N( b; o* p - " K d4 \. p. J5 o( l
- studioSplineBuilder1->Destroy();, p1 v \) t% T* D/ ]9 j
- ; w7 C* d/ |# U( w/ t
- return theSpline;$ U6 d- ?) C1 ^& T
- }
' D( d) n& }9 U - # X8 X5 S( ]. M, _/ a7 p% F: h X" w
- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)' |( m) p: ^% c+ ^
- {
, i# ]( N' V6 B& E! x4 ?. J - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
. z! ^6 t5 C* X* N - if (!thePoints.size()) return;0 l8 W# j7 L, ^* n7 O1 e- D
- 3 v( T2 p2 B0 F! g9 n$ ^: ?
- Spline *theSpline = createStudioSplineThruPoints(thePoints);+ C0 s: U+ M: l/ l' z; H5 v
/ X9 K m+ Q9 w# I- if (theSpline)( Q4 C4 V6 D6 [( h7 U9 ?+ Y
- {
' O8 K$ q# a- l" k - theSpline->Highlight();( N# N: \' G) h5 I( ~0 b& Y
- uc1601("Studio Spline Created Thru Points", TRUE);
1 L& X9 G* G0 L8 ~ - theSpline->Unhighlight();
/ m1 r+ P$ p% H6 Y2 c - }2 `0 D3 ^6 ]$ P F% @
- }
/ l' p; A& m( [1 j* V
复制代码
" }3 r* n& Y9 w
1 M F3 V' q* t8 e( x0 o8 d6 [2 F$ F' {/ D. n( A( a
|
|