|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线
- g- u! V/ j; U+ ]% g- #include <uf_defs.h>
2 B' w7 F! G+ S# k+ T$ d* O- k( Y - #include <uf.h>& H2 X l; D7 h, d! L% z1 R6 \
- #include <uf_modl.h>* V9 i5 T' m( T; L' g( j3 j
- #include <uf_object_types.h># P: ~* r/ d6 @/ C
- #include <uf_ui.h>
9 I# X- L: j' k6 Z/ K, v - #include <uf_modl.h>
q5 q n0 T( ]: u8 u( I+ y3 ^4 S - #include <NXOpen/NXException.hxx>7 z9 U7 z# S6 s5 Z/ _8 ~9 j6 C
- #include <NXOpen/Session.hxx>
$ C3 u: s z1 }, w) ?* ?% o - #include <NXOpen/Selection.hxx>. }1 r4 m. H. Z* h
- #include <NXOpen/Builder.hxx>
0 [7 I& p3 ]3 e7 s - #include <NXOpen/Features_Feature.hxx>
9 i/ t$ g1 `- Y - #include <NXOpen/Features_FeatureBuilder.hxx>
# Q" v) k3 M1 x( x - #include <NXOpen/Features_FeatureCollection.hxx>
5 C0 U! {5 L. x$ ] k- j, O3 d5 E3 F/ n - #include <NXOpen/Features_GeometricConstraintData.hxx>; z% x9 \. {5 h i
- #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
! W5 A7 M' X6 H6 @/ f - #include <NXOpen/Features_StudioSplineBuilder.hxx>
' n s3 d$ j8 G - #include <NXOpen/Part.hxx>
- f) w( h: i0 x$ B' n& f - #include <NXOpen/ParTCollection.hxx>) m- ^: l1 j8 a# ?6 m( e, Q3 M- ~
- #include <NXOpen/Point.hxx>6 U4 {* D4 Q. x& t% j
- #include <NXOpen/PointCollection.hxx>/ ?% k9 L( _1 ^+ [
- #include <NXOpen/NXString.hxx>. Z7 S. Q7 f1 w0 X3 M# V
- #include <NXOpen/UI.hxx>0 \# K. f6 X' _
- #include <NXOpen/Spline.hxx>! ^2 O% g! J( n4 K2 u2 R
- #include <NXOpen/NXObjectManager.hxx>
! G3 F e4 S% \) T6 s' \/ j
- I t/ w7 F/ f- using namespace NXOpen;
8 R* O# Z# h4 C0 d, w5 t - using namespace std;
F3 y: B. u3 n/ F0 C. R
9 R5 G3 A2 @& H- extern "C" DllExport int ufusr_ask_unload()& ]; E% y. j# h% }7 j: X5 t
- {; y4 u3 F- T4 Q+ y# X
- return (int)Session::LibraryUnloadOptionImmediately;
2 [, P G1 F+ z7 O+ h - }0 X: K5 Y: X: p D
- & y( Z6 G& r# D; z) g
- static vector<Point *> selectPoints(NXString prompt)
( X/ {# m f- I( r$ t1 k% {, k4 {8 a - {6 J* I* u# X: \% Q1 A. z" T- L% ]
- UI *ui = UI::GetUI(); M0 v) _- Z. N; G: j: Z2 g$ k0 G
- Selection *sm = ui->SelectionManager();! U$ S9 m% T' B2 q
- std::vector<Selection::MaskTriple> mask(1);
/ g7 i( `7 L9 ^8 ]7 S+ O - mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
9 h& R# k. ]4 S8 d! k" t; V - std::vector<NXObject *> objects;2 j( _8 m+ e6 h! I
- $ n$ ~6 P, K0 O; |! \5 V
- sm->SelectObjects("Select Points", prompt,3 h+ F& G! Z6 `7 I1 |4 ~
- Selection::SelectionScopeAnyInAssembly, ?+ m: F" V! r; t% U5 F8 Z. ^- R# A
- Selection::SelectionActionClearAndEnableSpecific,
8 C1 ~; k$ O4 o3 F* |5 V - false, false, mask, objects);; K$ v2 l( [; [1 q6 u
: C4 p# Q, @. Y- vector<Point *>selPoints(objects.size());
6 i4 g& e* U* K m9 p8 d2 f - for (unsigned int ii = 0; ii < objects.size(); ii++)$ _1 i# b6 e8 x7 {7 A6 z0 e2 `5 f5 H
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);. [ M$ A `- E% B2 x
- . d' _3 N: F6 C& _/ o. M3 m/ r8 s! c
- return selPoints;, `: H# {; K4 }3 J& K0 q# o
- }7 O# ?2 W# U2 q6 H
- ' w- n' w, c$ o( T8 Y
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
* U% n+ G9 ^1 {. r, } - {
, m$ b9 g7 Y: V# `) L; a/ {. P - Session *theSession = Session::GetSession();' h! e* b' P9 H% P
- Part *workPart(theSession->Parts()->Work());
8 [1 x, [ [) x$ V$ Z - 0 a% O. a/ W5 ~/ V& V6 J' T/ E
- Session::UndoMarkId markId1;
- q/ o; }! b, V5 J9 Y - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
" h- F) e! ?8 d+ h/ h0 d - "Studio Spline Thru Points");$ k4 [0 S P8 A5 x4 X- T+ N
- ; ~' \( E4 Y- P" w& I5 u
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);$ g% u+ L0 f( x4 Y. U
- 7 y; u7 e {; l7 m
- Features::StudioSplineBuilder *studioSplineBuilder1;% M2 p) U- n8 ^* \* A0 p
- studioSplineBuilder1 = workPart->Features()->; p& k& I. m: p' u/ O
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);7 s' _1 a7 T4 D a7 z- E
- studioSplineBuilder1->SetAssociative(true);
( K t( Q9 r4 a8 [ - studioSplineBuilder1->
2 K+ s# N9 O B& u$ o3 p7 V- |( h - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
4 {7 |( \* ?+ D; {" ` - studioSplineBuilder1->
; ?4 H' R, f. B% j - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);0 w3 c* y2 `* [* k1 j! b
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);6 }# b2 j* j2 u' W
- studioSplineBuilder1->SetPeriodic(false);
- g6 p% r) J5 i+ q% v - studioSplineBuilder1->
) q9 c* U+ v5 u( g$ D7 W) E p& p - SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);2 t; x7 X( o& {
- std::vector<double> knots1(0);) P# r9 x @! B" e5 d0 r: d! N
- studioSplineBuilder1->SetKnots(knots1);1 @* X& A( j( M! R6 \
- std::vector<double> parameters1(0);
& {5 R& }" _; ~" C - studioSplineBuilder1->SetParameters(parameters1);
" a6 H% v1 a3 V* g5 v. s - Direction *nullDirection(NULL);
7 z- P+ Q6 Q8 `; g0 F! N5 D - Scalar *nullScalar(NULL);
- n' L" \. }1 u0 I4 H" v# N - Offset *nullOffset(NULL);
& H1 b3 N, `0 w- t - 3 O. h- y( J' i3 f* X0 F0 \
- std::vector<Features::GeometricConstraintData *> c+ j2 r' B. L. h
- geometricConstraintData(thePoints.size());, Z$ x! R/ d9 M. ? k4 S
( j9 \; M: `8 D+ Y: f3 f$ x9 ^' u- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
: l# C9 K7 g! m4 ] - {; w1 u# w& g! ]& B# o: m
- geometricConstraintData[ii] = studioSplineBuilder1->: b! H$ y) H$ A3 ~) s; Z
- ConstraintManager()->CreateGeometricConstraintData();
# J% _: I; Y: I. \ - geometricConstraintData[ii]->SetPoint(thePoints[ii]);4 t- ?1 r) V. p0 ^' c L
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(, B' _% q3 O5 y
- Features::GeometricConstraintData::ParameterDirectionIso);4 |; M' B$ @+ ~' L
- geometricConstraintData[ii]->SetAutomaticConstraintType(
4 B- D |8 L1 i7 _# | - Features::GeometricConstraintData::AutoConstraintTypeNone);
1 ?7 l8 i0 t# B* X1 q. N: `- U - geometricConstraintData[ii]->SetTangentDirection(nullDirection);
$ f2 C6 Z% u: ?4 H2 l* d - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);6 v! {9 c( \( A$ u% e' O
- geometricConstraintData[ii]->SetCurvature(nullOffset);. u1 P4 {/ T2 [* Q0 A9 N2 x* f' e
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
/ D& ^' }, c3 g1 `4 W8 k - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
, \, N( @) b& y# @: q( ] - }& t- `7 u; q+ P: [
- 2 Y& i, p) T8 H9 m+ p# i; U7 p4 {
- studioSplineBuilder1->ConstraintManager()->SetContents(
2 B( o+ A# o, U7 Z" L - geometricConstraintData);, a' `! w5 U6 H* U! Z- {/ R
- ( E3 q+ w) \9 R3 F* G
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature(); `! I) R$ S4 F* M& W2 h
- Spline *theSpline = studioSplineBuilder1->Curve();
& Y! U$ V7 l, f: e4 f0 m - * O7 ^- q2 m; G: R7 H
- studioSplineBuilder1->Destroy();/ S z% K% ?) V* Y( O% A
- ( V% |- i" T0 \/ P* C v' Q
- return theSpline;6 T( v& I9 y" r
- }/ l0 W; m! P8 X" q3 q6 y4 m. J
9 b0 R1 S6 l, c- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)) G; Z- M( Z: j! x5 ^
- {: v1 J3 \3 r; F
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");: Z. P9 d. N7 X, ^" j* J; w
- if (!thePoints.size()) return;
; [( I! R& z& \' I
" F5 M, [2 a6 H; o- Spline *theSpline = createStudioSplineThruPoints(thePoints);
3 I1 P* \( [/ s5 a5 t @ - 6 X: Z; m0 T& S4 R
- if (theSpline)
4 R- A6 Z9 R* O2 B3 I4 w. F2 g - {0 B4 Q, l) s! m5 D- b
- theSpline->Highlight();
5 i6 B5 U( y: i0 Y; I; c! D - uc1601("Studio Spline Created Thru Points", TRUE);
, x6 L/ \; K5 r( m4 R - theSpline->Unhighlight();
2 t/ e+ ]* c' m. R) t6 v1 Z - }( C) d# J' S* G; K" R1 W- P
- }5 @6 W9 Z9 y. G) K/ R
复制代码
- w/ v& W3 T; y3 A/ p: W# |3 R' h% X# _5 B m2 ~) {# N
7 @ N6 C- Y' U, g- l
|
|