|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线
& X( c, H6 {: s2 p5 f- #include <uf_defs.h>" D1 S g5 i" @6 r
- #include <uf.h>
4 E$ A* E0 {3 {; X5 j! t - #include <uf_modl.h>
+ E5 K; m {' s - #include <uf_object_types.h>0 E7 T, O: P' V4 b7 `3 S! Y. f0 {! l; d) C
- #include <uf_ui.h>! l, m/ y2 e" S! C
- #include <uf_modl.h>
- \. O0 z i5 v4 U - #include <NXOpen/NXException.hxx>; Y* B4 T$ c* ?: x: V# W
- #include <NXOpen/Session.hxx>
1 A+ I& I+ }. S1 F! C3 @ - #include <NXOpen/Selection.hxx>" O( j B$ X- s: i* z. V8 z) B
- #include <NXOpen/Builder.hxx>4 N5 b, b5 F6 d/ ^% G: Q% H
- #include <NXOpen/Features_Feature.hxx>6 `) _: [! R/ ~
- #include <NXOpen/Features_FeatureBuilder.hxx>
. e- j9 `/ S; }) N4 u. v - #include <NXOpen/Features_FeatureCollection.hxx>
1 g2 M3 F9 n; Y! w7 u7 J - #include <NXOpen/Features_GeometricConstraintData.hxx>/ r8 f9 N6 C. S
- #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
$ K! P" b- g# p$ M/ ? - #include <NXOpen/Features_StudioSplineBuilder.hxx>, l* } G' a4 j; H; `) N5 w3 h
- #include <NXOpen/Part.hxx>
5 [8 L, V) x! y' d - #include <NXOpen/ParTCollection.hxx>0 y7 {" n7 g& G6 b g9 j7 H
- #include <NXOpen/Point.hxx>
5 q! t. z, t% n - #include <NXOpen/PointCollection.hxx>
) A" a. J) o% U( e: h6 C - #include <NXOpen/NXString.hxx>* D1 @8 C& ]. R" H, p, @1 ]! n! F
- #include <NXOpen/UI.hxx>4 S. G$ a7 F# j, r: n ]
- #include <NXOpen/Spline.hxx> h% |* {! c9 l t9 X- |
- #include <NXOpen/NXObjectManager.hxx>, d0 Y, x, V9 k2 U: l$ j
- / t- T. L3 q8 ` ~
- using namespace NXOpen;! X0 w# Q# n6 E! h. v7 z
- using namespace std;3 [8 V/ _, f- m! M
- W/ y" N7 V- M2 }" l) B' X. X
- extern "C" DllExport int ufusr_ask_unload()
, P m8 B9 t. w( a8 F - {# P o: K3 F4 J) c I2 }2 i5 E* d j' ^
- return (int)Session::LibraryUnloadOptionImmediately;
9 J6 S6 }+ s( L |: {- x - }
, U3 |' s( C8 }, T" R5 @
6 w. u% \. {7 \+ g% J+ x! Q- static vector<Point *> selectPoints(NXString prompt)
1 t( b; B2 c8 K8 e: O - {3 m( s, P- X4 C- w, D, Q
- UI *ui = UI::GetUI();$ w9 Z8 U" K! [' E) h" d, T
- Selection *sm = ui->SelectionManager();
; O) s% B& ~2 V- Z8 W8 k. p - std::vector<Selection::MaskTriple> mask(1);
" C1 e: \# n2 p* T9 g; B5 K% o - mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);9 @. Z" o; g/ r6 n
- std::vector<NXObject *> objects;9 s. r- w3 U( ^8 |( z& {# D8 x
- 8 C0 S& A& a2 m
- sm->SelectObjects("Select Points", prompt,5 w1 C- `8 ~0 P! c+ J
- Selection::SelectionScopeAnyInAssembly,
* K! B+ [: B8 ~$ H% H - Selection::SelectionActionClearAndEnableSpecific,$ ] C& a- P. W! o
- false, false, mask, objects);
; G( U# r8 X$ u9 f7 @* T8 }
% L6 M) X+ X% H- vector<Point *>selPoints(objects.size());% W; @0 L+ u7 @, K( q
- for (unsigned int ii = 0; ii < objects.size(); ii++)3 l: ?. ?" }3 r$ D6 f
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
# o, \! z7 P3 k' p3 V
! A/ i; U p2 {% P7 ~- return selPoints;
9 D. ?! V! Y0 T - }
5 n4 g' o" A! ~6 o, z# D9 J7 \ - 6 N9 }5 o2 T: A, y
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)1 }4 V; _5 E7 T& G) I
- {1 j( ]2 `# P5 Q5 `' \, V4 K
- Session *theSession = Session::GetSession();
# {6 E8 P/ Q8 M9 @, I/ W; W - Part *workPart(theSession->Parts()->Work());3 c8 l M' T7 p. t" g
2 d+ o$ q; y) R( M: O) w- Session::UndoMarkId markId1;. h, r7 V1 h" T# G9 ?4 U: ^( G
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,+ Q3 g" E2 l9 X" j- J
- "Studio Spline Thru Points");
; ?& `) f: E' H. o3 O( s
: V+ |4 J9 C% m( C& t- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
5 x: b% c. h' e8 h* U' g - 9 w4 w1 H7 U' v& d: r Z$ Q6 y) n
- Features::StudioSplineBuilder *studioSplineBuilder1;
" @3 J, O0 w2 n! l, L) B - studioSplineBuilder1 = workPart->Features()->
; q3 u# p% n( S: z g# U - CreateStudioSplineBuilder(nullFeatures_StudioSpline);
9 R5 ]9 P }2 | - studioSplineBuilder1->SetAssociative(true);) n7 v- |2 d: V+ U, T6 C: i% Y$ @
- studioSplineBuilder1->
) ~+ H8 ^ R, t! K - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);0 D0 [! X7 \" ]
- studioSplineBuilder1->
& I0 h; _# k5 h- s2 X/ U - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);4 q. b3 E+ b) h" b- }
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
. w2 S( e S) i. g - studioSplineBuilder1->SetPeriodic(false);! ^0 [8 X' s" R+ t9 T: w% o0 t5 N) I
- studioSplineBuilder1->$ T# Z) b" G2 e3 Z
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);% h5 E1 K* Q$ f: U' P
- std::vector<double> knots1(0);
, C9 L! c: ^7 g - studioSplineBuilder1->SetKnots(knots1);. H8 [8 @1 c, j
- std::vector<double> parameters1(0);
! E( O+ y @5 `; E: Y - studioSplineBuilder1->SetParameters(parameters1);
6 a8 b9 H, u) N" w5 e - Direction *nullDirection(NULL);
4 W- }7 j. {7 z' U - Scalar *nullScalar(NULL);; h& Q; T2 u* g% h# P: k7 L+ ]
- Offset *nullOffset(NULL);, l+ }/ v; O0 W" k0 L- h6 V2 d
- : s2 n3 l$ M, a, d
- std::vector<Features::GeometricConstraintData *>
$ X# V+ S, s$ {, U7 O( K. L - geometricConstraintData(thePoints.size());8 ~* b% X; D- Q0 k
- 2 n. R/ a/ M7 `1 m1 ]
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)" t, k' B6 ]8 [8 q1 C" g3 r- C
- {8 A4 G3 c2 V+ ?
- geometricConstraintData[ii] = studioSplineBuilder1->
" G% l& C' h( P, r - ConstraintManager()->CreateGeometricConstraintData();
, k4 f" V+ m2 C. e% h. u - geometricConstraintData[ii]->SetPoint(thePoints[ii]);
3 M, l5 x& p) ^5 v - geometricConstraintData[ii]->SetAutomaticConstraintDirection(
) @# w5 a# L7 O5 d- P - Features::GeometricConstraintData::ParameterDirectionIso);7 ?. p! t* I2 v
- geometricConstraintData[ii]->SetAutomaticConstraintType(
3 O4 t: l: Y7 W" P6 g3 a, e - Features::GeometricConstraintData::AutoConstraintTypeNone);
: `4 e' @; N+ a5 z& X - geometricConstraintData[ii]->SetTangentDirection(nullDirection);
% e% U7 u4 E! r - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);! ?: j- h9 _3 t$ O, p0 g/ x! @, d
- geometricConstraintData[ii]->SetCurvature(nullOffset);
+ {) [9 c- y' F) E& t - geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
@5 b% Z3 \- a& T: |: `5 Q - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
* q6 g; }) V: ?% h7 T% q* M - }
% y5 U. c! ?- t* V - 5 q0 K, X( a- O- j0 O! {
- studioSplineBuilder1->ConstraintManager()->SetContents(
7 ?8 s; D6 d/ u' e - geometricConstraintData);
* S4 B# T! V# `& K7 _$ W - % \% m6 |$ E9 z; W
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();0 z$ o, n7 u' U! W0 W
- Spline *theSpline = studioSplineBuilder1->Curve();. X) O" w0 l: W3 a
- % Y0 U: b) U+ a6 ~, G3 D
- studioSplineBuilder1->Destroy();' d9 D9 V! H. [; k
+ L0 f6 i: c# a$ I- return theSpline;4 c# ]0 T0 O% I& y- ]( @
- }
: {2 w% b4 P! i9 _5 m$ A" _ - a, M+ M6 R: Q4 Z7 `
- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
+ u& _ k y! {9 k - {
- ^' M7 }3 f) p' J! y# S2 f' _ - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points"); g$ _ V1 }/ q' ?2 C2 V) Q9 Y$ T
- if (!thePoints.size()) return;
2 B/ R3 Q$ U7 P. B* n; Y% p
3 B% b! F# E* G- Spline *theSpline = createStudioSplineThruPoints(thePoints);" D/ T0 d2 R9 H6 J6 t
- 5 f% f* Z. r$ e4 I' r
- if (theSpline)
+ L. y+ ~9 m0 m3 ?) [; H: q - {' G5 W/ ]8 i7 ?+ X& }( W+ s" t
- theSpline->Highlight();+ N- L5 f/ x2 l/ ~* r
- uc1601("Studio Spline Created Thru Points", TRUE);
4 Z% Z5 G6 N9 z1 b% ~# i - theSpline->Unhighlight();
' l9 ? j" f, | @) K5 Z - }; Z1 K" H t5 ^) r. g0 N" s
- }
+ h1 \& B& e2 `) b
复制代码
/ ]. M: d# H1 S1 J+ _, C. T: |7 y3 v0 Q3 P
7 o" f O N0 b
|
|