|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线
/ Z3 f: s* c% F* `- #include <uf_defs.h>$ T5 C/ C4 I/ v
- #include <uf.h>
+ B# Q' H) J8 u3 { - #include <uf_modl.h>
4 e! G, e; _6 N; q0 n - #include <uf_object_types.h>% s* a5 V7 \# D) t
- #include <uf_ui.h>2 S; G- b" c8 G0 v; L2 j+ I6 Y
- #include <uf_modl.h>0 y" i+ {* F9 m
- #include <NXOpen/NXException.hxx>
$ D! O" N% r: |' M6 ` - #include <NXOpen/Session.hxx>1 l! [, R7 W& V- Q6 N1 K
- #include <NXOpen/Selection.hxx>3 g2 c) a' E2 f- f, P& r
- #include <NXOpen/Builder.hxx>( v" c3 F K, p0 @- I; f
- #include <NXOpen/Features_Feature.hxx>
4 ?5 w, A4 x* |% F. l - #include <NXOpen/Features_FeatureBuilder.hxx>
% l% n" |, ~0 v0 W6 z% O* G - #include <NXOpen/Features_FeatureCollection.hxx>
. ?8 n; c0 ]4 J0 Y- K - #include <NXOpen/Features_GeometricConstraintData.hxx>: V6 b) c) }" b7 B( g( W$ N
- #include <NXOpen/Features_GeometricConstraintDataManager.hxx>. m6 c& _" x; O' V/ V
- #include <NXOpen/Features_StudioSplineBuilder.hxx>9 q! a, ?/ b- j4 } W- z& P Z
- #include <NXOpen/Part.hxx>
( K6 J, o5 `/ } p; ~4 b - #include <NXOpen/ParTCollection.hxx>! e" Q% V5 D/ u; c2 O0 e
- #include <NXOpen/Point.hxx>
H. ~- G! D0 k3 a/ Z, x4 e2 i - #include <NXOpen/PointCollection.hxx>
3 y2 Q4 C8 @, k6 d/ a; n, ]' h5 o - #include <NXOpen/NXString.hxx>
6 M9 A# Z$ j6 q* h - #include <NXOpen/UI.hxx>
0 o) b, p8 x" ^, D8 v - #include <NXOpen/Spline.hxx>, a# k7 s9 W( j" p* Q* e
- #include <NXOpen/NXObjectManager.hxx>5 c0 o" u' e2 s/ ]9 z. R4 e, _+ V
- , r( _8 q1 _3 E( A: M, Y
- using namespace NXOpen;
9 v& r$ X8 H$ m1 T ` - using namespace std;
) b) _' \% }+ `/ {- q5 r& z6 B
, O5 H9 ?* ~' \1 `: i$ r$ T- extern "C" DllExport int ufusr_ask_unload() m5 q4 S5 _* s6 Y' M# p- i1 t
- {1 U+ H: _6 j9 s$ p, p! t+ `/ k0 ~
- return (int)Session::LibraryUnloadOptionImmediately;7 K$ U$ v4 K0 [1 L* L
- }. n4 S; W: Q7 Y
( F) `+ k, q- u" H- static vector<Point *> selectPoints(NXString prompt)
: s' [3 P: _& V& h: d0 f, W - {
- {( h" }% A9 ` - UI *ui = UI::GetUI();
! ^4 l, z1 U. _2 J6 w7 O7 l - Selection *sm = ui->SelectionManager();
" t: k/ r! i- G5 c# K/ O3 s/ u - std::vector<Selection::MaskTriple> mask(1);
" B0 @5 b) B& S7 A: { - mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);1 {( k/ C3 K) O) P4 P r
- std::vector<NXObject *> objects;
6 b7 r- C) K+ @/ f& e% y5 p - 6 R+ y7 H9 @; U7 ]9 I0 N. r
- sm->SelectObjects("Select Points", prompt, Y* E$ ^5 Y; f" R% u
- Selection::SelectionScopeAnyInAssembly,
4 `: B+ O5 _* ~" O7 |6 l { - Selection::SelectionActionClearAndEnableSpecific,
5 B6 O9 r2 A1 C5 `# d. z - false, false, mask, objects);
% R8 u% _& d9 D% B' P
. A% n8 [# @' w/ z/ l: Q9 J- vector<Point *>selPoints(objects.size());
1 G$ f. M9 ?, G9 i, ~, O - for (unsigned int ii = 0; ii < objects.size(); ii++)* p# Z T( [8 t! @; f* {7 l B3 l5 y
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
]. P7 q6 G, K: A7 s- u: ]' t - / n) a8 K, \ Y+ l# f7 v7 @$ _. U
- return selPoints;+ L& }. @) r) Q: k
- }
' ~! y( k/ w: [: Q* C
V S3 u8 K; u, A- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
: Q$ E0 u; y' T3 L3 K/ F- ?* M9 h - {0 K/ f( ]8 y4 f% w$ e+ X, ~0 {
- Session *theSession = Session::GetSession();
) @+ \, @1 h! I A k1 Q - Part *workPart(theSession->Parts()->Work());
9 k' Z9 _2 v! B: {9 {
' j" Y+ z2 [, z" D5 e& ~- Session::UndoMarkId markId1;* a- Z2 ^- E: \! C( Q" o: E
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
' K$ z7 \( w# F3 N - "Studio Spline Thru Points");
- X, W5 F1 ?6 ]' ]& {; Y- V - ! k* m n. Y2 G% G! _
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
$ ~* C9 M' B8 g! c - - ^# d4 G5 o" k, y# O
- Features::StudioSplineBuilder *studioSplineBuilder1;
# H; T! f; W; X4 L |* n2 d& W - studioSplineBuilder1 = workPart->Features()->
0 X% J$ b7 n; M9 o* j' `2 G8 |: | - CreateStudioSplineBuilder(nullFeatures_StudioSpline);, f" G3 h$ I, t2 ]6 m
- studioSplineBuilder1->SetAssociative(true);
( J, d5 L, L) L4 V# v& S7 W - studioSplineBuilder1->
2 O" n7 M: b# Z4 x) E& B) o - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);5 Q1 R( P2 x: l* ^1 ? u) j
- studioSplineBuilder1->6 j1 ?" U6 S* C+ u# _# E/ j. I
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);% a% y4 V- A0 h/ \% m( q6 a
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);7 |; x1 i1 A% _% j; T
- studioSplineBuilder1->SetPeriodic(false);! |, z$ Z% M, t" Y" l
- studioSplineBuilder1->$ ^) W* Z8 e; |! d8 x: e* U
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);/ e* Q. w G9 w) h) P7 U1 Q
- std::vector<double> knots1(0);& e+ E. ^4 o4 g' [/ c/ Z+ Z
- studioSplineBuilder1->SetKnots(knots1);
+ ]: z+ E# j$ \ - std::vector<double> parameters1(0);
8 E8 [) }" E4 _' _+ d/ z - studioSplineBuilder1->SetParameters(parameters1);) ^* Y6 J9 f) ]! F( I& V
- Direction *nullDirection(NULL);
" D- W0 \2 x U! E) N% N - Scalar *nullScalar(NULL);
/ ~! d. m" p- l& v' \* E5 o: [ - Offset *nullOffset(NULL);
, c' E4 n1 B: ?7 X
0 O' x) P3 @2 W, X) {- std::vector<Features::GeometricConstraintData *>7 S& |% V7 _9 |1 N0 l; ]! |8 m
- geometricConstraintData(thePoints.size());
6 M9 z4 J) p' l h
. Q1 a+ I7 p4 O" ?0 H5 y: ]- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
$ R; z4 M7 B6 T0 Q" B5 u( Y - {
& h d" j/ B6 N6 n7 g: M - geometricConstraintData[ii] = studioSplineBuilder1->
U7 K, {7 i! @' _( m% G2 E2 Q8 K. e" I - ConstraintManager()->CreateGeometricConstraintData();
! `! v9 T- C* S# O4 {$ W - geometricConstraintData[ii]->SetPoint(thePoints[ii]);* ~+ \9 H7 Y% q* X
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(: [* x7 p8 F- }9 z+ H$ R
- Features::GeometricConstraintData::ParameterDirectionIso);
7 ]2 G9 k+ S e; ~) ^6 u - geometricConstraintData[ii]->SetAutomaticConstraintType(
+ N5 E/ M7 L h' ~2 _! x: P - Features::GeometricConstraintData::AutoConstraintTypeNone);
# J- {. U3 M. Y+ K - geometricConstraintData[ii]->SetTangentDirection(nullDirection);+ r, u3 Z6 ?" x5 Z% p
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);" ~' |: j7 j) x9 p
- geometricConstraintData[ii]->SetCurvature(nullOffset);9 `) \5 J: O7 V. T% K
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);$ S8 B" X+ J4 I: P
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
y% A" O! \# v' Y5 _7 r - }2 O5 L" Y2 T9 j( I4 N y* x
- 1 E1 i5 [3 O% P- h
- studioSplineBuilder1->ConstraintManager()->SetContents(
! D# N0 F2 B% W6 S$ j. r8 @+ E - geometricConstraintData);
% Q+ g1 k' k# {2 }2 [& y! y/ e1 F7 t - % z6 M4 W# u' s: ~0 M# o) Q
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
1 Y3 Y& s1 B$ k, L - Spline *theSpline = studioSplineBuilder1->Curve();
* I }$ [$ Q2 H
8 [" Z; I. t t2 R5 l0 @/ L3 r- studioSplineBuilder1->Destroy();
+ I4 a7 f2 [6 p8 {7 Z: F, s9 E0 d
+ B" P0 L6 |' x! H5 p5 l* N- return theSpline;; }/ U0 ?8 r& S' Z3 D
- }7 E; J; r( g/ G3 k& Y' T; h
- - m2 _8 r, A2 [! G
- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)4 i) T, q! ?; ~7 _. P: B
- {! |2 F! R1 q4 h/ n0 S0 X1 e
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
8 D& ^: ~7 X' {' a - if (!thePoints.size()) return;
8 r$ L* w! _( ^1 b7 c - 2 r; X0 {0 N8 M" v; w2 K+ }
- Spline *theSpline = createStudioSplineThruPoints(thePoints);
) c, ^! p X- A6 `/ d& ~ - ! `3 k. t J6 r
- if (theSpline)
+ H5 T+ a6 T; }, R; X3 ?7 ]1 { - {
3 a. w/ a" D H - theSpline->Highlight();6 }# ^& Y) Q# p7 ^" ?; E9 S0 r
- uc1601("Studio Spline Created Thru Points", TRUE);
$ h% s0 Z' K! ]. Q6 f - theSpline->Unhighlight();
" p* I1 G) {' C; H' I - }6 E5 @* Q5 A3 U! `
- }4 H9 \+ K7 w1 s) b
复制代码
7 m6 Q, E3 m6 W" O6 y" V. U" W7 [3 x$ s; e
: ^+ y# d, s# [5 U4 L0 r, w/ s$ d) ]* }
|
|