|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线
: V0 h, z5 v& f) H- #include <uf_defs.h>
# w% T a O: n/ S" @5 S - #include <uf.h>6 }; a8 q% V. I
- #include <uf_modl.h>
, B$ O% @3 U& l$ }6 s- g - #include <uf_object_types.h>
3 `% w$ l! o R4 `% d1 J - #include <uf_ui.h>
. R4 m1 Q0 n5 V* g& b - #include <uf_modl.h># x \, o4 W" N/ f1 P
- #include <NXOpen/NXException.hxx>' H& u8 ~9 j1 }0 @9 S8 ` v
- #include <NXOpen/Session.hxx>* ]+ K# f/ a$ K, Z
- #include <NXOpen/Selection.hxx>
) V2 }; R% `: Q% n4 R* A - #include <NXOpen/Builder.hxx>
1 i9 D0 n- Z: }, A - #include <NXOpen/Features_Feature.hxx>, o5 h. ?; P; M5 D* _8 Q2 l
- #include <NXOpen/Features_FeatureBuilder.hxx>6 z' {9 M! ?, Z
- #include <NXOpen/Features_FeatureCollection.hxx>
: F& O- F$ g4 Q% H - #include <NXOpen/Features_GeometricConstraintData.hxx>- `/ ^' ?7 i3 n2 O4 T6 h
- #include <NXOpen/Features_GeometricConstraintDataManager.hxx>: D; K" F g# \* I. V" L
- #include <NXOpen/Features_StudioSplineBuilder.hxx>
1 B7 P8 E! z8 d+ @4 x. Z - #include <NXOpen/Part.hxx>
+ p( h0 r( r$ r% ^ - #include <NXOpen/ParTCollection.hxx>( j* ~: d0 p. A" p1 U+ n
- #include <NXOpen/Point.hxx>
0 s4 L |0 I! Q4 |; a5 k9 K - #include <NXOpen/PointCollection.hxx>
v b. k6 I0 l+ b - #include <NXOpen/NXString.hxx>
3 W8 c- c$ W2 I" `$ R/ } - #include <NXOpen/UI.hxx>( ^" R- k$ t, {0 K5 i6 W
- #include <NXOpen/Spline.hxx>( P$ Z. @% K* e3 N
- #include <NXOpen/NXObjectManager.hxx>7 \: ]/ t% y7 G! q
6 L- x7 A5 Y1 K3 F7 V" g: g- using namespace NXOpen;
* p" E- F6 a4 l( X- @5 x% | - using namespace std;. C/ F# s( D3 M6 D$ t& |" a
( v1 K$ |2 i- k% h6 @7 {* s0 K- extern "C" DllExport int ufusr_ask_unload()+ o. O* s# \- Q( S- Q5 o
- {
9 O) [) H+ E! H3 a) q4 J - return (int)Session::LibraryUnloadOptionImmediately;
; u- j# \1 u+ M+ X9 |- T8 y) c! W - }
) s9 X2 E* T1 u9 w7 O - ! y- E& t7 k) @" r& f
- static vector<Point *> selectPoints(NXString prompt)/ u" A+ |7 B8 v9 n& c8 u7 v
- {
1 F0 f% Y1 p. u5 g* J - UI *ui = UI::GetUI();3 |& l& ?0 [. W) ^4 J$ A8 r
- Selection *sm = ui->SelectionManager();
6 N/ w: _, J: H( J& h- n - std::vector<Selection::MaskTriple> mask(1);
% [( v# l( ` R A - mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);" ?: C; ?3 o5 ^3 v4 R* v" M
- std::vector<NXObject *> objects;
* v" H& L, Y( u' B! Q6 h5 ^ - 9 d, e! G* P' S2 R
- sm->SelectObjects("Select Points", prompt,- j+ H; V- F: A' u7 R( @
- Selection::SelectionScopeAnyInAssembly,7 i% Q. b; H; D- I- y3 Q+ O" l m0 z1 x
- Selection::SelectionActionClearAndEnableSpecific,+ ~( L* c/ e' s: [0 |4 n
- false, false, mask, objects);
5 `2 B4 Y: ^2 c$ D* a - , v! Q; C% S; j
- vector<Point *>selPoints(objects.size());
* {' X4 D. w% c2 V) F' z - for (unsigned int ii = 0; ii < objects.size(); ii++)
i- `- i+ H1 u3 w4 t0 c1 a - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
- L8 l8 ]$ y3 n3 e" d- V
5 L$ g, @# S8 t! h4 G, W. ~: M4 k- return selPoints;% U( ?& H3 X" b6 R! o0 s
- }
7 ?' _- S6 O. a! x& w - ! e5 Y" I" J4 v7 s- M" n
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)( A% Y& q* j$ t" x; O+ M
- {+ h# s) ^6 F) {% | [
- Session *theSession = Session::GetSession();
& X6 z1 N) o: g$ H - Part *workPart(theSession->Parts()->Work());
( I! _, }5 ?& h8 K) G
4 a# k$ j, D' r) e# d& o- Session::UndoMarkId markId1;
. Y2 l& ^" \, b, T- M+ M$ U - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
0 U3 n# F! Z! H/ g6 ^ - "Studio Spline Thru Points");6 v0 W6 X4 L! n; m, u" }7 [
- 3 u" J' i! r) K' H0 o
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);- v, r e# }( A* v1 P
0 U) u+ K: t# Y6 \% y- Features::StudioSplineBuilder *studioSplineBuilder1;- K- Q1 R1 a) \
- studioSplineBuilder1 = workPart->Features()->1 I( V+ \( A; K+ A: ~* A
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);3 ~: l: G% ~3 `5 J
- studioSplineBuilder1->SetAssociative(true);
, w8 p: ]: A p6 B - studioSplineBuilder1->& z7 T7 [" b6 P* Y* {0 d
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);. u$ v) u/ _8 z4 M
- studioSplineBuilder1->4 ?2 I2 c. T2 R% p! U$ g3 q
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
9 m* o8 [/ Y8 Z, t2 I; } - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1); o5 W6 q+ I( V7 F8 Y3 T: [
- studioSplineBuilder1->SetPeriodic(false);* U3 H- i! U0 G4 W" n" v$ U/ r! D
- studioSplineBuilder1->
* L2 r( Z z( I. _- L2 I' F - SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);) n" ?" u2 q& Q7 n" ?
- std::vector<double> knots1(0);( h) C4 U) M/ J" `. b- y# b) S
- studioSplineBuilder1->SetKnots(knots1);
# {) R7 J. p; S3 B! w4 _% m - std::vector<double> parameters1(0);& \5 y, `; \; Z* h8 l
- studioSplineBuilder1->SetParameters(parameters1);
- r3 d1 L* p' N2 ~) [* k3 D - Direction *nullDirection(NULL);
- E X! t* ]6 y% V0 G2 ^4 @- y - Scalar *nullScalar(NULL);0 C1 A: h0 k* m
- Offset *nullOffset(NULL);2 m' E! I7 x m# k
- ! r5 @3 |( J- M+ t
- std::vector<Features::GeometricConstraintData *>* @* K$ K: H: I8 s
- geometricConstraintData(thePoints.size());
$ W6 x' C- m9 j5 |* L5 e8 ? - , u" r# c% R8 N
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)1 r) z2 h/ K: Y+ |; C9 U
- {
5 w; q$ s8 B4 C - geometricConstraintData[ii] = studioSplineBuilder1->
+ x# s7 T; W$ M" X/ n - ConstraintManager()->CreateGeometricConstraintData();. i8 c0 |4 w. j: Z
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);
) @1 {" M6 t L6 S# ^* z( b+ e* x - geometricConstraintData[ii]->SetAutomaticConstraintDirection(1 \7 l8 y; g) m4 }9 B$ y
- Features::GeometricConstraintData::ParameterDirectionIso);
3 l/ Q- F/ Y8 ]- A- T - geometricConstraintData[ii]->SetAutomaticConstraintType(( y$ E4 P! |/ M# v# i M
- Features::GeometricConstraintData::AutoConstraintTypeNone); z$ U, x. [; |1 A$ j) o
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);( N1 P. Y. i$ b h
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);! u: Z: Q, j) R
- geometricConstraintData[ii]->SetCurvature(nullOffset);
( Z1 S7 W' p+ r - geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
* }$ }+ m4 O3 P) r* ? - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
9 S! X+ Z& p. @% v# Q7 r. T - }
1 ?5 b% M% G% o2 |; N - # i0 R1 J. T- | R% q
- studioSplineBuilder1->ConstraintManager()->SetContents(0 a4 l; J# |2 o# d3 J, x8 y8 F
- geometricConstraintData);9 P: X3 |5 p1 F* S# p3 x) ?
$ C2 \2 a, O6 H0 I U- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
9 [1 o1 I: H8 E - Spline *theSpline = studioSplineBuilder1->Curve();
6 E2 R% p$ y+ j; Y$ }0 O - % b/ z: U: M& `. y3 Y
- studioSplineBuilder1->Destroy();
. Q9 g/ F" [% C( a, B$ m - 0 \5 x6 h6 U# K U1 C# L; Q
- return theSpline;
% \% d- l" N$ i4 S$ d& f/ Q) M - }
% A: A- o4 ?$ R: U; p
! S( Q$ L7 d d9 y) @5 J0 v- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
4 i* g8 m3 m2 Y7 O" d, s" g! z - {
/ E* O! b; ?, z3 ~& {" e - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");1 Y6 ~8 ?; m% r. ]
- if (!thePoints.size()) return;
# r6 F& U# U8 c) {
+ F( z1 `8 T& f6 ]$ m% _* C; g- Spline *theSpline = createStudioSplineThruPoints(thePoints);, w* i+ T6 q' u6 o# ]0 r$ y$ W
0 O; l3 y$ d% B& W. t0 Q# h9 h- if (theSpline)( E1 P" R1 X8 o& Y4 T5 B1 k% F0 w
- {
: H( V$ p' v& a. Q3 F+ Z- X - theSpline->Highlight();
8 J* G, _. G, ~" p( Z5 f8 r - uc1601("Studio Spline Created Thru Points", TRUE);/ i4 m! s! [5 n8 I* Q
- theSpline->Unhighlight();0 W0 ^9 J1 E, d' k( Z
- }8 u: B, a7 G* s+ @
- }3 P" V. U1 `1 G1 U% X$ _3 T% L: e
复制代码 4 _; h; A, s4 ]: X+ m g7 x
, g9 M3 l o& I& _! E$ h
. f2 E3 b P" d: s |
|