|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线
1 t- c5 R% i+ C- #include <uf_defs.h>
6 x+ F: ^: F: P2 Z; _/ K0 ~ - #include <uf.h>* f5 y( n! K5 ?2 h4 I
- #include <uf_modl.h>' W# q: x8 k$ v6 q. d. L1 Y
- #include <uf_object_types.h>
1 b6 W4 J- j5 t I2 k - #include <uf_ui.h>
) P p# s0 ]6 J( ]7 `0 r - #include <uf_modl.h>! l( F/ F' G" E0 b
- #include <NXOpen/NXException.hxx>
" t' J' ^+ f j) F - #include <NXOpen/Session.hxx>- N" B. ~. o4 v8 [) M) O
- #include <NXOpen/Selection.hxx>
* A6 [8 |1 E4 X" [" P( ~4 f- j l - #include <NXOpen/Builder.hxx>
& H/ q7 q+ W6 e- ] - #include <NXOpen/Features_Feature.hxx>
3 k( G* |7 z6 }. `0 N5 m - #include <NXOpen/Features_FeatureBuilder.hxx>8 m }4 n$ E; x @; V8 O4 W. c
- #include <NXOpen/Features_FeatureCollection.hxx>) w1 b1 X5 d. W* B! Z% b
- #include <NXOpen/Features_GeometricConstraintData.hxx>
( p: [* p( M4 h' ` x' Z7 [ - #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
7 E+ A% ^ k* p1 I/ M/ g4 Q W - #include <NXOpen/Features_StudioSplineBuilder.hxx>
0 s$ W( v, o2 F0 Z7 C9 K - #include <NXOpen/Part.hxx>% S6 O% w i) }0 H5 s
- #include <NXOpen/ParTCollection.hxx>
. A0 G! |8 }- [8 l. g/ G2 K9 c/ y1 U4 s - #include <NXOpen/Point.hxx>
& @6 d5 {5 M5 u# d - #include <NXOpen/PointCollection.hxx>
3 q- u5 I; J- m* J/ @: i$ n+ j" O - #include <NXOpen/NXString.hxx>- L' h& k! @4 x; W3 e6 z" m7 |
- #include <NXOpen/UI.hxx>
* j5 d! C# ]+ Y4 A) j - #include <NXOpen/Spline.hxx>1 t+ }1 @* F9 {' N4 ^( h; s
- #include <NXOpen/NXObjectManager.hxx>- A1 b1 g- W# r1 ~% R5 o: m, q" @
/ g/ c Z! d2 ?& f# ~" J- using namespace NXOpen;; K& C; w8 ?1 Z' I1 r6 S% S
- using namespace std;8 m8 v7 Z7 e( d! n: \
C, t+ Q/ P% v- S- extern "C" DllExport int ufusr_ask_unload(), n# D X C/ D W% U
- {3 B ^8 U9 \/ l# r" o
- return (int)Session::LibraryUnloadOptionImmediately;/ h2 j. G, o- D0 |* [
- }1 n2 w: Y, J3 q" S% |% i
- & Q2 }- K5 j; h$ D/ @- J, q8 C
- static vector<Point *> selectPoints(NXString prompt)
5 T, d% [% U, v( z0 X) L: s - {
+ i0 o$ z9 P: r - UI *ui = UI::GetUI();9 c7 K6 G/ ~6 L0 n( n L: S! L* N9 o
- Selection *sm = ui->SelectionManager();
) a5 j3 u; ]% \1 K: e/ C O8 X - std::vector<Selection::MaskTriple> mask(1);3 P4 r9 G; E3 y% v
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
$ W& j* B0 W0 P6 J3 y0 N6 H2 J - std::vector<NXObject *> objects;) v" Q: q+ D2 W& {& E. `9 u! [
' @+ o% ^% Y3 O% E8 t8 i. _6 q- sm->SelectObjects("Select Points", prompt," a9 z, u8 c, M) o4 J9 C1 P/ H
- Selection::SelectionScopeAnyInAssembly,' k* M! v; j1 o% }! Q4 ?2 f) G+ z
- Selection::SelectionActionClearAndEnableSpecific,
7 A3 G2 M3 Q8 K3 @ - false, false, mask, objects);
) J( B ]. K# ]4 A7 W
" a }8 _" s% ?! w8 O4 U/ r. R- vector<Point *>selPoints(objects.size());
* |3 H7 F8 `7 }, y+ x2 ]+ N. |0 U - for (unsigned int ii = 0; ii < objects.size(); ii++)
' Y. l" U& h3 P4 |4 g8 A) e - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);5 P* O0 G' U# I, l
7 T, M( M) F, @$ ]" f9 z- return selPoints;
9 P( k& c4 u1 n; y$ n D8 A+ _# O - }
1 i4 ^6 _8 {3 C8 U- `9 \
' E3 h; f8 s! i0 A1 f- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
/ Z0 Z: H" r" X6 n - {
9 U: n2 ~1 b) u5 L+ f6 r - Session *theSession = Session::GetSession();
( E( g' M m7 y* w9 S: {- ~ - Part *workPart(theSession->Parts()->Work());( ?& T! E! G( g8 a! `
- 7 k7 |& h/ D& J1 V0 M" i
- Session::UndoMarkId markId1;- |. l; P7 o6 W8 \+ e* e: G* n# f4 c2 b
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
6 V) F' p/ j- M2 U; ^# B& { - "Studio Spline Thru Points");
4 w4 W( p4 g4 x, K Y& l) E - 0 O( A6 i3 x r. ~, E; W4 c2 n. U
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
+ }! l& M( q: y$ z1 |
0 X; M0 @" }" F+ Q$ d5 k0 p- Features::StudioSplineBuilder *studioSplineBuilder1;: O3 O. c1 d7 T- K. q; W; b+ ?
- studioSplineBuilder1 = workPart->Features()->% j/ ?) @4 G" a# v( p3 X
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);
" F5 t6 d; v! i! F0 E, h/ s1 \ - studioSplineBuilder1->SetAssociative(true);
: d, F& L/ h- D - studioSplineBuilder1->
# N8 M- k! N' L d* t% r' ?7 ^ - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);) O& X2 w9 i) o, a" N9 r
- studioSplineBuilder1->. p+ [+ s+ K* ~7 T0 D/ X3 V! Q
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
( D( z9 R E$ H3 V( L - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);: e) G- I! u( W) F
- studioSplineBuilder1->SetPeriodic(false);# r. N9 I) i& s+ a5 X; h
- studioSplineBuilder1->
9 s5 z2 i! ?6 w' c1 S - SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);% e4 J+ O# M: D. i- Y; W3 D! T
- std::vector<double> knots1(0);+ E* ~' A" u6 Q0 [+ |2 g+ S& V {1 l% |
- studioSplineBuilder1->SetKnots(knots1);
" e7 C. A; W5 V8 Y* z - std::vector<double> parameters1(0);
" G$ l ?1 @; t N0 p7 S - studioSplineBuilder1->SetParameters(parameters1);
3 `0 |' q+ T2 u* y7 ^6 R1 a - Direction *nullDirection(NULL);
p: O) \3 w; O1 w& T - Scalar *nullScalar(NULL);# h6 S0 D) i$ {
- Offset *nullOffset(NULL);8 F' ~- v0 z$ V7 [ m% f
- % s, h! f- A+ A% v8 b' l
- std::vector<Features::GeometricConstraintData *>
+ \( Z2 }+ H0 s4 g$ m6 S- U - geometricConstraintData(thePoints.size());2 v# m1 _8 a, ~ R$ L/ N
- % R# m- X# k. J' D+ E; f1 ?
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)2 r/ I }2 ^0 B% z
- {+ c% i/ ~0 F$ B5 O' x& l5 S
- geometricConstraintData[ii] = studioSplineBuilder1->
P* n( L P3 U* z - ConstraintManager()->CreateGeometricConstraintData();
7 u- X; j' P& Z% W; G: {2 z - geometricConstraintData[ii]->SetPoint(thePoints[ii]);
0 n: E; H" Q, b+ ?/ R4 C; V. y- h - geometricConstraintData[ii]->SetAutomaticConstraintDirection(' P) K# c3 R! ^: ^7 e/ T
- Features::GeometricConstraintData::ParameterDirectionIso);
# q# P" I; ]- {% Y6 N - geometricConstraintData[ii]->SetAutomaticConstraintType(
9 a6 g9 J, i% \1 ^6 s - Features::GeometricConstraintData::AutoConstraintTypeNone);
6 U! {3 C" H- t$ I2 W - geometricConstraintData[ii]->SetTangentDirection(nullDirection);- A5 D* m# Y% {6 h# M* I& N
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
/ k0 M M6 e# r" D - geometricConstraintData[ii]->SetCurvature(nullOffset);# c! w* L) U2 k0 w4 `8 C
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
$ d. _0 s4 z) w6 M - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);4 [, u/ W' K: F- {2 m; l, q5 K5 O _
- }
2 ^4 c6 u2 z$ X* C2 F: w
% s+ M2 ~) p. {3 K- studioSplineBuilder1->ConstraintManager()->SetContents($ v5 R$ I5 N! O- Z4 t: R! D
- geometricConstraintData);3 _! h7 _1 P" L% K) |0 F
- ( c/ j' o: a# ]0 n6 o
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();, p7 U. k9 i h5 b+ E5 U0 K
- Spline *theSpline = studioSplineBuilder1->Curve();/ _% I& e! A+ c. ~+ P; E3 C
& f( n. l' a' ]% L# X( ~+ y* G0 X- studioSplineBuilder1->Destroy();- h" I$ A9 g% G
- & R6 F8 U" O/ @2 ]
- return theSpline;
" L: r/ t+ L y( j8 e4 w - }7 A7 I0 e- f2 M9 f9 f2 t5 W
- 8 o7 d T! e( @+ S5 g4 h
- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
0 N, y8 I* b6 L# \7 i/ M - {
7 ~+ M0 l: |2 E# k - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
6 P; q7 `$ z6 c - if (!thePoints.size()) return;
1 p S3 x% g6 T! W6 I) P
, y& x: f( y: I. F' `# b* ^- Spline *theSpline = createStudioSplineThruPoints(thePoints);
) r* ]4 ^7 ~7 P& T( C# }$ t
t" R1 V7 r/ |( } E0 d; m- if (theSpline)
( J P+ p) [# b" J# J) d: l - { o. l6 Q/ |* T6 c% e
- theSpline->Highlight();/ ]: j% f3 F: ^+ g8 y
- uc1601("Studio Spline Created Thru Points", TRUE);
% o- B, D5 V- L- f4 r - theSpline->Unhighlight();
& b5 V2 u" s/ Q" a - }
9 A# `6 W3 j, O4 r, ~ - }
, f8 e" D0 a4 c2 w8 [/ N6 m
复制代码 7 v/ }. A4 a/ u: K$ {' U8 q. n* A
/ c+ H5 J Z3 N9 E0 I& E
) b& p2 o5 H/ p* U$ \ |
|