|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线
7 ~2 O( ^& q) @- Z& ~/ `! u- #include <uf_defs.h>
& _" K0 c3 r8 N. r- L - #include <uf.h>
: Y4 a) j/ _" _7 l& d - #include <uf_modl.h>
J+ b$ k: a; ?" _/ D3 ? - #include <uf_object_types.h>
6 @& e; _2 U' U0 `& Z1 e - #include <uf_ui.h>
( R0 G/ D5 h8 A" {3 ^8 j5 @! v - #include <uf_modl.h># ~9 O* V: b- @: \3 B, r7 g
- #include <NXOpen/NXException.hxx>! S' @8 p9 _$ x) d
- #include <NXOpen/Session.hxx>5 u5 x4 \( a- z
- #include <NXOpen/Selection.hxx>/ N0 j' v* B: d1 {% B) R6 x& l
- #include <NXOpen/Builder.hxx>" i( ~; t2 z I8 y9 P
- #include <NXOpen/Features_Feature.hxx>
9 \; s2 h# s4 `8 V: U# ` - #include <NXOpen/Features_FeatureBuilder.hxx>* i8 \/ ]6 k2 R, [7 G
- #include <NXOpen/Features_FeatureCollection.hxx>
0 P# X$ n ] i9 ^+ \5 @ - #include <NXOpen/Features_GeometricConstraintData.hxx>/ v7 q" _9 c, Z1 c- c+ f
- #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
) Q: H; N- j% d# v; v/ P" V4 h - #include <NXOpen/Features_StudioSplineBuilder.hxx>
9 l' v% ^! q/ l% ^ - #include <NXOpen/Part.hxx>% p5 {1 ^* U6 u
- #include <NXOpen/ParTCollection.hxx>
\5 e. q$ ]# p/ u - #include <NXOpen/Point.hxx>6 J! t' e/ d& k& Z3 E, U
- #include <NXOpen/PointCollection.hxx>
# n' G1 I$ ^: v" O) S4 W$ p - #include <NXOpen/NXString.hxx>
% O; J1 F1 ^+ w - #include <NXOpen/UI.hxx>
0 X+ [/ L9 ~* G" |, K, F0 G - #include <NXOpen/Spline.hxx>
J& @5 w% y$ Y S# T - #include <NXOpen/NXObjectManager.hxx>, k* w5 c" d" k [8 O2 C
- x" H) |# u! k/ L" |( T2 \7 P- using namespace NXOpen;
& g9 T. H4 ~# e% P! b' y- q - using namespace std;
$ {5 n5 k: w( G - $ N# \, x% c, M# g* b1 {/ F8 U
- extern "C" DllExport int ufusr_ask_unload(); G) |% c8 H( `6 |4 i; e1 p
- {
# _) t) t8 ?! ~- w# s( D" i - return (int)Session::LibraryUnloadOptionImmediately;$ i o b# x& S% L# J9 f
- }
/ c' u8 r) k3 m O$ F7 T1 r1 a - % Q- _* {! A' ?2 i
- static vector<Point *> selectPoints(NXString prompt)
5 o& G8 c% ^' @9 p+ g7 W - {
* v! D: S$ _' U& A' J - UI *ui = UI::GetUI();
, h! `6 }' v1 ?. l& d - Selection *sm = ui->SelectionManager();) e/ Q! M" e* h
- std::vector<Selection::MaskTriple> mask(1);
3 ^; g/ t$ [8 \0 ] - mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
7 J' I: t5 W# h - std::vector<NXObject *> objects;
3 b* c6 ~, Y/ O0 p( c8 b - ! s3 ~7 E6 j& B2 p& R4 v
- sm->SelectObjects("Select Points", prompt,
# n. Z. k4 W) x* i - Selection::SelectionScopeAnyInAssembly,
6 Q2 [: ]9 w" }7 f) S' l0 i - Selection::SelectionActionClearAndEnableSpecific,) ~, L9 m. X* z+ h. I
- false, false, mask, objects);
: x8 d& g" C5 e$ U' a
% U! j. d3 ^: h+ A& K' s/ l0 I* e- vector<Point *>selPoints(objects.size());" t: B B7 n9 u3 u; x" I/ D
- for (unsigned int ii = 0; ii < objects.size(); ii++)- E# r& x' n6 h! H% a% X# y1 @
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);% e; W$ N& {; {2 n
0 F4 t: i5 t+ S+ n) W% s- return selPoints;
6 d4 c" _* Y* \6 ? - }
* G" ~# J+ }5 q6 x- Q! \
- e; r6 G) }) n! F1 V' u5 A- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)3 D/ e5 O& {0 K3 H$ O4 P1 O! E
- {
% \# \" k$ T1 M9 T9 e9 D - Session *theSession = Session::GetSession();
* T( |& Y2 H2 O* x9 a- N. V9 W; r - Part *workPart(theSession->Parts()->Work());
- y1 m0 j% A1 {' S( w# K - : s, C% _. [$ \
- Session::UndoMarkId markId1;
- H6 ^& A* G3 h' p- v) Y - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
% i& L- c( m; x: O9 A; ^! @, R - "Studio Spline Thru Points");4 p8 V* H1 H* u: j& m
- ! U8 B7 d" n) ?6 q5 V9 G; V
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);* m+ @- v% j2 t7 H- l6 l
- - z _$ ]2 M! D7 _8 c$ a
- Features::StudioSplineBuilder *studioSplineBuilder1;
8 E6 |2 c- P' |4 q - studioSplineBuilder1 = workPart->Features()->
7 C( B( ^8 n# v, J - CreateStudioSplineBuilder(nullFeatures_StudioSpline);
/ M! I) D7 S& P& i$ w0 s! w# o0 @0 J4 E - studioSplineBuilder1->SetAssociative(true);" I2 O' p$ ]# }3 A" d
- studioSplineBuilder1->1 s* J8 [* T, m i: m# M9 r
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
% l, k# l. y# @. M - studioSplineBuilder1->" n$ F$ h" I9 c" U4 J
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);* w. t |# Y$ }
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);! Z6 @0 M7 J, X# V5 e" P! f0 z
- studioSplineBuilder1->SetPeriodic(false);1 T5 B+ ~0 A2 Y
- studioSplineBuilder1->* W( D, s( n' J% H
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
- ?% v9 ^0 M3 E# a - std::vector<double> knots1(0);
8 ~; T* |8 [# g6 n - studioSplineBuilder1->SetKnots(knots1);+ i0 ?* x x) |0 _
- std::vector<double> parameters1(0);/ d* F4 d/ G# D' T9 g
- studioSplineBuilder1->SetParameters(parameters1);5 I; c& E8 F1 ?! U& b5 ?4 g2 N
- Direction *nullDirection(NULL);8 L# O& X5 H7 Y8 r' L
- Scalar *nullScalar(NULL);. m2 i9 \. F1 e* L- a, B5 K
- Offset *nullOffset(NULL);3 c# ]3 v7 c9 y& X$ ~& {
6 ~: I d6 O* y F, S1 s" [2 L0 V- std::vector<Features::GeometricConstraintData *>
3 _0 y' d2 w! U; W/ W! R - geometricConstraintData(thePoints.size());
( T+ u6 ^7 A; G) a8 A! I - - r/ o/ k1 R0 C. d
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
6 F; S# z9 G, J" J1 q1 k - {; O& W; Y- M) K3 h) C9 |
- geometricConstraintData[ii] = studioSplineBuilder1->2 }$ z% ^9 p, x% I# d) ]
- ConstraintManager()->CreateGeometricConstraintData();5 z' o3 O0 o" h
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);8 D8 u. b. `& i `
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(
, g8 H3 d4 N3 S2 d - Features::GeometricConstraintData::ParameterDirectionIso);
" T5 ~- D4 Q! ^, F1 c" S - geometricConstraintData[ii]->SetAutomaticConstraintType(( u8 d( |) x" ~1 e
- Features::GeometricConstraintData::AutoConstraintTypeNone);6 {% f1 o5 @3 O, Q: g& `2 }
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);4 S- L9 x" j% I
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);7 E9 j/ }& t7 f) f6 [4 X' t; p
- geometricConstraintData[ii]->SetCurvature(nullOffset);: l; w% t8 ~- i& [5 `* O
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
4 m$ w5 l/ i) S) \& A( l# r - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
9 w. u. r2 }! B/ Q9 E: h - }( T! ^, Y' N* `( k
3 O+ i# l9 W' g( D/ J- studioSplineBuilder1->ConstraintManager()->SetContents($ U n/ U, s- o: B0 k
- geometricConstraintData);
6 R/ F+ A- M( D k8 i, p - 7 Y- R5 @' p+ |0 c6 a0 ]
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
# D2 Q! G0 P" j: @- n- R8 I - Spline *theSpline = studioSplineBuilder1->Curve();0 f8 N) L& I- f' J2 o+ T
9 z Z9 R- e7 p0 i+ F5 v- studioSplineBuilder1->Destroy();
8 R$ i- l+ _* I
0 g, a, `: N1 P$ y' A- return theSpline;
/ s0 w; y7 S0 _1 h1 ^8 h4 E4 A - }" Q0 M( \, ?3 p! v
- 4 _, S; U) O3 T" o* M9 H( C
- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
) s) @ Q8 l7 I1 f, U. q4 {* K2 F+ S - {
, z, f3 O! C" A6 \$ @9 I, n - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");& g: g4 A9 ~! Z7 l! ?! Y l- G. i
- if (!thePoints.size()) return;
9 H7 q# ~, u% ^- A" O7 D* D - " L8 P6 _+ S7 e7 m4 ?
- Spline *theSpline = createStudioSplineThruPoints(thePoints);* e1 V! r8 Z9 X! X, I2 J# d
! `+ h! f( y. q/ S- m2 ]- if (theSpline)
6 C9 u" W# r8 F) ?: \: A - {
* Q2 k2 R m! b) g4 K - theSpline->Highlight();
5 q# |! `, M% W: C4 i7 q7 C3 H' u - uc1601("Studio Spline Created Thru Points", TRUE);' W) b0 V; C9 i$ \
- theSpline->Unhighlight();
% g# ]1 K' g4 P8 a( Q5 D - }
+ I% B+ _% u) |1 v, y - } v" p% L& P' Y. X
复制代码
6 m6 O$ l) W4 m# O; k5 c3 A6 F
3 F: i" \& |; l* O; S$ e6 h% J% N5 V) w' l2 a/ o$ t# m
|
|