|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线
; @# ~# e$ f* I0 D- #include <uf_defs.h>6 e& Z$ ]# P1 c/ H4 e9 e
- #include <uf.h>2 @& x* {+ @3 C% g( i
- #include <uf_modl.h>
' B$ w0 `; g# b- ~) m( A, ` - #include <uf_object_types.h>; A# A1 U& W; ~2 t
- #include <uf_ui.h>4 I5 d% I: h" b8 q8 W+ d
- #include <uf_modl.h>
9 Y: ^7 Y J" J - #include <NXOpen/NXException.hxx>
6 q% P+ w2 J1 N Z5 y, y - #include <NXOpen/Session.hxx>
Y$ ?4 V9 K9 i9 ?" f; ? - #include <NXOpen/Selection.hxx>
. ]( @9 W6 K9 U2 d. d2 p - #include <NXOpen/Builder.hxx>! {2 i) e; X* U& q5 ^5 }- f5 I
- #include <NXOpen/Features_Feature.hxx>- t$ s" n2 C/ q
- #include <NXOpen/Features_FeatureBuilder.hxx>/ g% f! [4 g" V o
- #include <NXOpen/Features_FeatureCollection.hxx>
% y ?' W1 \2 b( K& m3 s3 h - #include <NXOpen/Features_GeometricConstraintData.hxx>, i6 l5 A/ ]. f- m) l5 C8 |
- #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
" Y6 |9 P6 {7 s$ Z7 D) A - #include <NXOpen/Features_StudioSplineBuilder.hxx>
* O1 S$ x# ^! C$ T/ f' X - #include <NXOpen/Part.hxx>
! W% U5 L2 e2 y+ ]% I' o) \ - #include <NXOpen/ParTCollection.hxx>
* `4 t1 O- P" O! z8 v - #include <NXOpen/Point.hxx>
- O, L) A# w9 [+ y) I, U4 J - #include <NXOpen/PointCollection.hxx>$ D/ g7 }" Q6 {7 i- i, e7 b0 _
- #include <NXOpen/NXString.hxx>4 [7 P' h. v& j9 q
- #include <NXOpen/UI.hxx>
3 s3 _6 o2 J4 Y% v - #include <NXOpen/Spline.hxx>8 w2 _+ z6 M B* v
- #include <NXOpen/NXObjectManager.hxx>
/ n( }( n& Q; S- z2 p7 N% g9 y" h
+ a& `7 ?3 u; C, n. X+ z- using namespace NXOpen;
$ ?" R4 {# H8 Y2 z* U7 ~( O4 \ - using namespace std;- ?% G6 Y! k, g* a2 K
- & \* s/ ^3 l4 U; P) T
- extern "C" DllExport int ufusr_ask_unload() B+ ~3 D; o4 {
- {" J( L, m2 w: T; U! c$ Z3 D
- return (int)Session::LibraryUnloadOptionImmediately;
) h: b: C0 A' i ~0 c - }
, B2 ^. u9 k5 q/ [2 |8 v7 c) b
" P( f, P( U& N/ F8 q- static vector<Point *> selectPoints(NXString prompt)% p$ U! A b) Z J
- {) J' Z. o8 ?5 t! q% Q( t
- UI *ui = UI::GetUI();
% P- U. w/ c8 s5 T. D" F - Selection *sm = ui->SelectionManager();
' L, T( z6 {/ K9 l- T* Y - std::vector<Selection::MaskTriple> mask(1);+ \* n% E- R1 |: O8 C
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);* X3 q! p9 r5 q& {
- std::vector<NXObject *> objects;6 V* [% s+ d* T7 |7 p. V
- # M2 G3 A( i' v2 G
- sm->SelectObjects("Select Points", prompt,0 w/ e$ _" X$ h2 N$ X2 o# L+ t& D
- Selection::SelectionScopeAnyInAssembly,
) o! L) R! ]* P3 v2 x - Selection::SelectionActionClearAndEnableSpecific,
( C% B9 u! b0 ]; c6 t: ]7 d9 u - false, false, mask, objects);+ P0 b, O1 B! I/ ]' a
- + ?7 g4 ?! i5 B5 Z1 z% o
- vector<Point *>selPoints(objects.size());
( ~/ Q% I+ x0 W7 }+ B, G" Y- q' ]6 V - for (unsigned int ii = 0; ii < objects.size(); ii++)
4 U( R5 N7 e$ U. u- A: p. F% d - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
5 t$ U) Z8 T' c( v! `
7 e$ R( y# G) ?5 A1 } I$ O u- return selPoints;
- J$ e, [) t+ ~( [0 A5 P2 U - }
8 D4 x! M5 ?2 r" J' M" ^ - : K, x6 a7 Q0 _) v5 t, S
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
) e, M/ h' W( s$ @5 p( x6 y, y0 v - {3 Y/ Y0 N: |$ Y
- Session *theSession = Session::GetSession();
" C$ w3 q7 b" K+ i, o* C - Part *workPart(theSession->Parts()->Work());% D- |% b1 b( m/ y6 F+ i/ z
- 3 q: R& B5 `$ C7 d( I+ S0 Z
- Session::UndoMarkId markId1;/ B4 R- m& \+ w% J9 K4 U
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
+ o, a% A, K s; Q7 ^2 ` - "Studio Spline Thru Points");
# t x" m4 C. K- M - ( u% ^. A5 ~% v6 C3 D* S( l
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
S$ ]: R! a9 G, Y) E - + o% G- g* |* x
- Features::StudioSplineBuilder *studioSplineBuilder1;
. Y/ d" n2 w: c; u5 u! L7 t+ A - studioSplineBuilder1 = workPart->Features()->& n8 O) J7 L, m$ e2 m( f$ v
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);
' J- D- y* y ^- }' G - studioSplineBuilder1->SetAssociative(true);
9 Z5 R1 q, }1 K f. T3 w - studioSplineBuilder1->7 R4 M9 m' N" ~* x5 o
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
1 |. V! M' |" h) \1 p% L4 X - studioSplineBuilder1->
0 @5 G- P3 j. d- i* N) ?" y1 g - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);' S! E6 P2 g8 [) O
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);! u( f" I/ w/ O
- studioSplineBuilder1->SetPeriodic(false);. |2 W4 N: O6 m3 F$ M/ X
- studioSplineBuilder1->7 Z8 K; X1 A- k% ?( N
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
: {* _- X8 K2 l9 k - std::vector<double> knots1(0);) ]# Z* v7 X; P: n
- studioSplineBuilder1->SetKnots(knots1);- @6 |/ M! @- \) o
- std::vector<double> parameters1(0);
0 ~& Q+ Y6 t& z) t/ m0 Z8 ^7 R - studioSplineBuilder1->SetParameters(parameters1);" b9 r+ Q+ J) k; j8 n' l
- Direction *nullDirection(NULL);
+ p: z( d: j9 M - Scalar *nullScalar(NULL);- L. k) D: O9 s' d& U3 r/ Q
- Offset *nullOffset(NULL);1 k( g# F' {3 {' i2 G* S7 G: s
3 p' S2 l* Z' x+ j1 t- std::vector<Features::GeometricConstraintData *>) l* K: ~( \: }, d
- geometricConstraintData(thePoints.size());
% x9 z9 X; ~6 I# T% Z t2 A
$ ~$ A0 D6 y- \ D- B- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
/ ?; p: n. K$ `2 F - {5 r3 |& o4 b+ o8 ~
- geometricConstraintData[ii] = studioSplineBuilder1->
* ~3 {% K+ p" O* i- d& A - ConstraintManager()->CreateGeometricConstraintData();
. j, m! m7 k5 y4 q e. e" k. r - geometricConstraintData[ii]->SetPoint(thePoints[ii]);
9 d0 d: m2 X; D+ Z' i$ x - geometricConstraintData[ii]->SetAutomaticConstraintDirection(
) W9 B: {! y. z - Features::GeometricConstraintData::ParameterDirectionIso);
6 j. p1 f& ^1 \5 I3 |1 |, V5 m - geometricConstraintData[ii]->SetAutomaticConstraintType(
' H- {' N; m5 m - Features::GeometricConstraintData::AutoConstraintTypeNone);0 S8 R8 z$ H( F# n2 h/ T% n# G! g2 c
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);
% ~" r- N' ]- y+ M# C) a$ C - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
* ?+ ]1 d4 U$ p' W - geometricConstraintData[ii]->SetCurvature(nullOffset);- `' C+ M, [$ j% S$ h9 i( _+ e& q
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
3 A( E8 B; u6 p1 @! A* W - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);) }$ _3 b8 D! a
- }
8 G7 U/ W5 c" j2 ^6 u - + |# l3 s- r- k. m0 z, X
- studioSplineBuilder1->ConstraintManager()->SetContents(
* Y' i* Y' t: R - geometricConstraintData);- `# ?; L# @5 ~5 w6 ?: P0 e
- ) ~) w- M5 C+ g; m3 r" q9 ?3 P
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
' }6 g* [6 c% A1 L" c J& U - Spline *theSpline = studioSplineBuilder1->Curve();
) Z8 N$ f; _4 {) |" N
& L' J# b# k2 @8 i" e- Q- studioSplineBuilder1->Destroy();
+ j. I5 l7 s- z) G& D. N. o' C - " m0 b M' u7 Z9 W
- return theSpline;
5 z& @' t c: T4 e - }2 B& c- v u# N! e- B1 s
* q4 f- Q f) l! P% F& A- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)+ p8 H; t5 _/ n" R# `4 d
- {4 y/ r2 F9 m. F2 R; {$ v$ u6 I; }% _; y
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");( _1 a6 ^. H( l: e
- if (!thePoints.size()) return;
0 G1 c: h' v% q4 d7 j - - _* `. t) L0 N7 O U0 t2 N. Y
- Spline *theSpline = createStudioSplineThruPoints(thePoints);9 L" i Z4 ?+ e; Z
- " w" Z9 j" ?# @! O
- if (theSpline)
: Q, y% |9 H! O& o' k5 h" H - {' r8 Z6 d# V6 a
- theSpline->Highlight();5 @2 v& d4 G% J" ~" r* K Q
- uc1601("Studio Spline Created Thru Points", TRUE);
1 n9 y7 ~/ @5 s, _: ]& |. z3 |$ G) Y - theSpline->Unhighlight();
5 y; l* j9 d# T' {' N+ v5 J$ R - }
# Q. p/ |6 f$ f - }& \( \* b4 `! Z
复制代码 # o5 Z$ p5 M; }# I3 v6 Z
* j% `$ F- G5 r2 L& V9 h& U" M; ?! e, R8 x- V) i; _' W
|
|