|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线
9 G" `2 Q* u2 f: s# @ v- #include <uf_defs.h>
9 ^( T) |' L1 O - #include <uf.h>6 S) U( |2 X+ A% W& }. K
- #include <uf_modl.h>
* h: C) e9 W. t# D - #include <uf_object_types.h>" D+ A& y9 e$ o. |. X/ P
- #include <uf_ui.h>$ n! R( Q1 E: G" m; E: W+ N+ `5 J
- #include <uf_modl.h>
Q0 ]) C& E" Q# d - #include <NXOpen/NXException.hxx>
' L U0 x; M: [! G" `" g - #include <NXOpen/Session.hxx>
" m& c! M6 Q6 e% X b# ~1 U - #include <NXOpen/Selection.hxx>
) r' r. E4 K& L2 v' I$ F - #include <NXOpen/Builder.hxx>6 D7 i5 A" ^/ W. @, f5 A
- #include <NXOpen/Features_Feature.hxx>. m2 B9 U# o- U2 u( @# R
- #include <NXOpen/Features_FeatureBuilder.hxx>
+ j6 i' m" ~* f9 P: W2 O - #include <NXOpen/Features_FeatureCollection.hxx>
! e9 S' c9 v- S* E/ N$ L6 u' f% A - #include <NXOpen/Features_GeometricConstraintData.hxx> `9 W& l& `9 j0 Z) @) H: f1 R
- #include <NXOpen/Features_GeometricConstraintDataManager.hxx>) L8 e) F7 ~1 K% @& W, C2 ]
- #include <NXOpen/Features_StudioSplineBuilder.hxx>
" }9 l A0 S F M" x* j# F - #include <NXOpen/Part.hxx>6 A } O5 |) x( ^# _9 a" [6 W
- #include <NXOpen/ParTCollection.hxx>
! l4 A' ^- s+ }' Y2 v& j6 m# z" G - #include <NXOpen/Point.hxx>
2 q( t( Z$ O/ d6 j - #include <NXOpen/PointCollection.hxx>
( k) W% Z- i, k" o; M7 @( t - #include <NXOpen/NXString.hxx>% U- ?4 s$ t- D- E, W9 G; A$ c
- #include <NXOpen/UI.hxx>$ m Z7 n8 o* t6 A, W& g+ G0 C3 c
- #include <NXOpen/Spline.hxx>9 V) a* l7 g% n- W
- #include <NXOpen/NXObjectManager.hxx>8 ]- z! A! f. c
1 r" R8 p# x; U( `+ ^$ H) k- r" w7 j- using namespace NXOpen;
4 P6 c: Y8 M j8 r6 u% O1 \- E - using namespace std;2 E# d& j2 z' w Q6 @. ?( v8 z
- ( S. Q8 ^8 \; y' L1 u$ [
- extern "C" DllExport int ufusr_ask_unload()
! C8 f/ @8 @" Y9 N! I - {
8 p( o0 C# ^; R: W - return (int)Session::LibraryUnloadOptionImmediately;1 r3 c6 o7 T$ E3 i! n) Q6 w
- }0 l4 s2 \, m0 n$ o4 h8 y* _
- 4 l% g: m; G }* W& n* c
- static vector<Point *> selectPoints(NXString prompt)
/ S8 P3 R8 _. ~ - {
1 [/ Q0 U% Z1 C% t4 M6 M( K - UI *ui = UI::GetUI();! Q, D: E" I% w' m
- Selection *sm = ui->SelectionManager();- J: h2 b) {! j( @+ x" y! O
- std::vector<Selection::MaskTriple> mask(1);
4 l* c' b8 f- x9 e* E7 `2 ? - mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
2 Q( [# _( T5 S" [3 ? - std::vector<NXObject *> objects;* ~- E3 }" L! K: N7 n7 W" x0 ^" x
- : E7 `5 s$ W; R/ Z. G
- sm->SelectObjects("Select Points", prompt,
E6 B9 b* b7 [% @. R1 ^ S+ } - Selection::SelectionScopeAnyInAssembly,
2 [3 i ?$ b2 n! b4 s r5 r0 E% E - Selection::SelectionActionClearAndEnableSpecific,
3 w1 [1 C) L2 ?3 i# F - false, false, mask, objects);8 W2 Q# G1 I. c9 I( W
7 M4 w& Q. J: i- vector<Point *>selPoints(objects.size());* b( Q5 V* U N0 `6 T# o! w# F8 ]. J
- for (unsigned int ii = 0; ii < objects.size(); ii++)6 G; W* C+ e* q+ }
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
) ^% |( k7 {+ Y. ?9 Y5 n1 H5 y
' c& g. m! p1 R& Z# C# c' H O, D# x- return selPoints;/ Z$ r f8 a0 S) F. ?' n: r' g
- }# ^, A* I5 i, h/ D' y" c3 R
- 9 S, z& R2 ~9 I9 K/ i
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
& ^2 V% B4 l! i7 I4 l$ r1 v6 D - {& l. j/ m9 e6 k! R7 ~: [' ^
- Session *theSession = Session::GetSession();
+ D: S3 Q6 A9 _( z% i, z7 u - Part *workPart(theSession->Parts()->Work());
/ u Q) h, M+ t- S
9 L2 }! |1 h2 ^$ `9 c- Session::UndoMarkId markId1;! h0 @& D& M" o
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,$ }. w1 @: m% D C
- "Studio Spline Thru Points");
3 A9 j- Q7 e& \$ v6 C - . u5 P+ K% q, {. t a
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);, M; ^) P k, {. L( D
; p1 g T: ^% l5 ^0 n" q* @- Features::StudioSplineBuilder *studioSplineBuilder1;
& z+ Q1 c/ B9 w/ v - studioSplineBuilder1 = workPart->Features()->
' P7 U5 L. }. S" B - CreateStudioSplineBuilder(nullFeatures_StudioSpline);4 l9 [1 ?) J' m/ |7 i$ Z( ]4 U
- studioSplineBuilder1->SetAssociative(true);
7 p" i7 M! I: | c6 u, y9 O* } - studioSplineBuilder1->
1 p* P6 J. O! l1 s( ]% h" | r1 K - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
& `9 D1 t: z! |0 k6 \ - studioSplineBuilder1-> d+ C9 z- G" Q/ `# z
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
4 |. s4 q0 z& j; Z3 G1 w5 D - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);* `2 h* A6 m; w( I
- studioSplineBuilder1->SetPeriodic(false);" ]4 ]& p" L' ~- }- j2 ~ `8 }
- studioSplineBuilder1->$ ?3 U% o! ?& a% o& D/ P4 B: z0 _
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);/ w% w% p. U0 `! r: o
- std::vector<double> knots1(0);
% `; D* Z. n5 o5 L' H9 s1 `$ J - studioSplineBuilder1->SetKnots(knots1);0 p( H7 E/ M% i( k9 V9 s+ C; t
- std::vector<double> parameters1(0);
! y* a" X3 e6 g - studioSplineBuilder1->SetParameters(parameters1);: T; z( N0 B: \: H7 b" E
- Direction *nullDirection(NULL);& N: [) I% }- d# V1 `! v
- Scalar *nullScalar(NULL);
/ r0 e2 i/ ]. ]; m7 j3 ^ - Offset *nullOffset(NULL);
% A) g: l5 Z) z: ]1 v - 1 z3 C; o4 Z) L
- std::vector<Features::GeometricConstraintData *>) q6 B0 X" ^* a0 u
- geometricConstraintData(thePoints.size());! c$ W5 n% X4 Y6 s Y2 b! a3 H
- 3 F. Z4 q6 S( P5 q" X9 w
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
3 [/ [+ m7 _0 G3 ]+ @ - {
- u8 }5 J3 z+ `: \' N1 O - geometricConstraintData[ii] = studioSplineBuilder1->
% p: p; [9 W# S5 u" Q - ConstraintManager()->CreateGeometricConstraintData(); b3 D: C) |5 r0 s
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);, S0 h$ I D- l6 o3 L. {
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(
& K6 E6 n1 t2 O, |# C - Features::GeometricConstraintData::ParameterDirectionIso);+ D# [2 H" h% e3 y6 U5 }* X( }- M
- geometricConstraintData[ii]->SetAutomaticConstraintType(
, N" h8 ^7 W% X, V5 |. }2 ?( c - Features::GeometricConstraintData::AutoConstraintTypeNone);
# p0 t$ y+ @4 I5 x1 [ - geometricConstraintData[ii]->SetTangentDirection(nullDirection);# ?8 y: a5 G: D- Y7 I, ^
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);+ y" I; K' }1 D; z# q5 G8 Q9 s, g
- geometricConstraintData[ii]->SetCurvature(nullOffset);, x0 \: a1 }; y$ w$ V4 v
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
& v9 R2 y' Z0 _ H9 v1 \ F - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
* e/ S& G2 F. Z1 B- G$ [1 v5 d) h' W - }
/ A$ K2 d# \/ X) z: v) p - ! w3 t8 u- { F0 g/ ?4 ]8 F( x3 C
- studioSplineBuilder1->ConstraintManager()->SetContents(
1 W/ Q8 q5 @( j, e$ g( H3 b - geometricConstraintData);# ^9 }+ g Q( B- @* R. H5 u
- $ g. k, w+ h7 L
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();3 m" c0 V0 z6 v/ q# o# I
- Spline *theSpline = studioSplineBuilder1->Curve();! u3 C5 q4 ~; x+ s! i* w2 o
$ t3 l1 |( L" Y/ t' ~+ g0 L- studioSplineBuilder1->Destroy();
) W6 H7 P( B5 B: q
7 f" J' Y+ a1 Z+ B8 V, p! | z- return theSpline;* W" z% p. Q) S# @0 m) J" a. N1 T
- }7 i' e% _/ t8 c0 ~: P9 a5 t: W2 J
- " f" H0 {+ ~6 E. `3 b! L+ h
- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
$ P. g; L! r% @6 O - { O1 I& C% C' i: l
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
8 m( e7 W! k, ?+ F. } - if (!thePoints.size()) return;
, q- z1 S4 G$ g+ x
/ W5 z; f8 | L8 |- Spline *theSpline = createStudioSplineThruPoints(thePoints);! \7 N; r" C! i- m8 _
- 7 R4 b; `' ]) L3 x( F) s s; @
- if (theSpline). ]7 U# B4 r0 q+ T$ F
- {, Z. }# { m& Y) B% A* P0 K3 O8 C
- theSpline->Highlight();
: u+ q9 q% b! o9 g3 V* C6 c3 c% N - uc1601("Studio Spline Created Thru Points", TRUE);
9 L4 ` A) I# C( M: S6 P% Z! [: O - theSpline->Unhighlight();, H$ o7 ]/ N: B. D. N
- }, k# C( c3 h0 H/ R
- }
. ^$ q O2 b2 b; n- i
复制代码 & ]" {6 \# k1 W3 N3 n% l* H
, c# M9 m) R4 K! r6 g8 ~5 c
* Z5 n! g2 p+ k+ _( V8 {
|
|