|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线
! |2 N! C$ S, K, T: u( `/ f% ?' i- #include <uf_defs.h>1 H1 a( ]2 o$ I! o
- #include <uf.h>
& {0 u: w+ W! ~$ z& G1 j - #include <uf_modl.h>5 u+ L; H, ~5 G- _6 M! o
- #include <uf_object_types.h>1 ?/ E+ {, o- i- d$ s- s U
- #include <uf_ui.h>5 ~" \) p: s( e% L
- #include <uf_modl.h>- R( M5 Q! i, {3 j
- #include <NXOpen/NXException.hxx>
" J. p) \2 P9 P8 m* D2 P - #include <NXOpen/Session.hxx>4 V; B2 ]3 Z" _* A" H
- #include <NXOpen/Selection.hxx>
7 y. H/ f: q: s - #include <NXOpen/Builder.hxx>2 j4 {( Y: K z; A( Y* u& K' c7 V
- #include <NXOpen/Features_Feature.hxx>
6 N2 S" k1 _% c' V4 M0 y - #include <NXOpen/Features_FeatureBuilder.hxx>; b$ l3 J0 {4 w& T/ k) p6 o# C
- #include <NXOpen/Features_FeatureCollection.hxx>) _. i$ i1 k$ o* s1 y7 c- x5 R
- #include <NXOpen/Features_GeometricConstraintData.hxx>: w; q" W0 {: f# X8 k4 P
- #include <NXOpen/Features_GeometricConstraintDataManager.hxx>7 Y. `9 R& q0 b. L8 E! T' a8 ?
- #include <NXOpen/Features_StudioSplineBuilder.hxx>5 @2 W( X" N. }4 Z3 R
- #include <NXOpen/Part.hxx>3 h6 ]0 u8 |' w
- #include <NXOpen/ParTCollection.hxx>
; d/ ?/ N; a$ E; _: \+ {9 y - #include <NXOpen/Point.hxx>
; u4 f' R3 s% s0 f( l - #include <NXOpen/PointCollection.hxx>; c4 M- Y. P$ V' {1 [ _$ G
- #include <NXOpen/NXString.hxx>, @' a3 D: o8 E
- #include <NXOpen/UI.hxx>
5 ^) ~! g" h# T7 u: C& Z - #include <NXOpen/Spline.hxx>
0 [) }* x$ w& P; y - #include <NXOpen/NXObjectManager.hxx>
) c+ R) J: f8 [! B6 p - / {1 U% z; `% A- L' Q
- using namespace NXOpen;
( y* [; P5 A9 s) \/ ^) O - using namespace std;4 v, k" M1 p' k; f: k
- 7 y* ]5 w. I; [9 q6 T2 N
- extern "C" DllExport int ufusr_ask_unload()
( _+ H* V! r+ X) h T, m - {
# W" y" u8 b. M A1 Z5 @1 c; T5 e5 x - return (int)Session::LibraryUnloadOptionImmediately;! g& |* @- z$ o4 ]8 Z
- }
0 i. f. i# o9 I c: V9 |' A - % u0 f4 w; e7 ^6 k) I, d) X
- static vector<Point *> selectPoints(NXString prompt)
/ i5 w" }6 e% } - {
* _( b& k- N" ~ m4 f8 [) \+ e - UI *ui = UI::GetUI();3 R( _. P6 B) X( Q2 ?: c9 B* @
- Selection *sm = ui->SelectionManager();; e* A! u9 N8 z
- std::vector<Selection::MaskTriple> mask(1);1 N* w- d8 d0 M i3 J% ]
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);. h( O1 @' A' z
- std::vector<NXObject *> objects;% \6 W9 {" ^5 ]2 r! Q9 d, E' v
- - ~) e: s% ~1 A" Y
- sm->SelectObjects("Select Points", prompt,/ C T& C, s, y4 N6 Y
- Selection::SelectionScopeAnyInAssembly,
7 W6 [& i" y) e1 U/ p2 j2 _/ S" y6 N! X - Selection::SelectionActionClearAndEnableSpecific,
7 G. s" R/ E1 m4 k) d& k - false, false, mask, objects);* l" q! a% u$ V
# y4 n# E; z8 s" z4 N N1 m1 g- ]3 {- vector<Point *>selPoints(objects.size());; ]% O* B, i4 M; j {4 r
- for (unsigned int ii = 0; ii < objects.size(); ii++)
! z9 `9 x# o8 l- `( r6 s. ? - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);1 v# r6 x0 }5 Z: V- o7 }
- & u8 w; M; }& {2 ^
- return selPoints;! }" w- f" U3 B! O/ p
- }
2 T8 B7 d9 O! K2 ?3 h7 J5 E
8 J) M3 ~7 ]2 a- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)! c# X: } c/ ~# f1 C9 }
- {0 N& F! V7 b5 H! z8 Y
- Session *theSession = Session::GetSession();
, K+ }5 A$ ~9 v/ R' `. F - Part *workPart(theSession->Parts()->Work());- P$ d6 g* \: z; g* T! T$ u
- . D7 x& a, z* N/ N
- Session::UndoMarkId markId1;
, l" r8 R, Q0 ]6 ? - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,$ U' ?8 c8 G0 C* Z
- "Studio Spline Thru Points");
9 ^6 u" |" [4 Q( e. V- g. J - , E0 D; Q/ s# z5 D$ X; ~ p* p
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);( p0 ^$ T0 ^0 ]( X& Z
, P I( \ G& }* \# a- Features::StudioSplineBuilder *studioSplineBuilder1;! b1 g) C- @7 B" K
- studioSplineBuilder1 = workPart->Features()->
7 D: N3 n6 H3 C7 I, f2 b3 Y+ D - CreateStudioSplineBuilder(nullFeatures_StudioSpline);
$ X& E. h) E$ l% Z8 N) |8 m4 i# N - studioSplineBuilder1->SetAssociative(true);
* k' z0 q9 [0 F. T - studioSplineBuilder1->) [' X) N" d" p; N0 y
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
/ |& s; Z j' g M - studioSplineBuilder1->
7 c; _5 G( @$ z- c, W - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);8 R5 c3 h3 N; ^! G) J! I
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
+ R+ A/ V7 }8 c" S5 i5 c0 K- B0 ] - studioSplineBuilder1->SetPeriodic(false);
1 r; w; n5 d: L$ K9 g0 C - studioSplineBuilder1->7 ]8 A1 W- L6 T9 R
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
% q. v4 @6 Q5 ?( ?2 {5 r - std::vector<double> knots1(0);
- ?4 S% U9 m- u - studioSplineBuilder1->SetKnots(knots1);% g' Q$ \2 R0 u; m7 P, D
- std::vector<double> parameters1(0);9 A$ U) G4 V# O6 T! V& U
- studioSplineBuilder1->SetParameters(parameters1);
( R+ r3 h& j3 x1 E+ g - Direction *nullDirection(NULL);
# t, d" k3 j, v$ @ - Scalar *nullScalar(NULL);
% |6 t0 \8 A3 P5 X7 N - Offset *nullOffset(NULL);( r# n; S5 R3 `( z, d }- `
* G% w: A, T8 p4 g- K- std::vector<Features::GeometricConstraintData *>
" I( E* K, ?+ p% ` - geometricConstraintData(thePoints.size());% R7 h! ~, a9 i" B& O
- $ y+ D) N6 ]9 d6 v% d9 H" ]7 \6 M7 k
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)8 K, U* U& L$ o, p0 V A
- {$ Q6 r( ], w6 U* g( x
- geometricConstraintData[ii] = studioSplineBuilder1->) |/ W! _; A. t; a- k6 g
- ConstraintManager()->CreateGeometricConstraintData();& v: @" P4 w& P& @! D
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);
5 o p$ l8 x! `( S/ Q7 F- s - geometricConstraintData[ii]->SetAutomaticConstraintDirection(2 I# O( l8 s; Y! k1 p2 m1 g
- Features::GeometricConstraintData::ParameterDirectionIso);* t* h+ F/ Q+ |; d- v5 f
- geometricConstraintData[ii]->SetAutomaticConstraintType(
o0 f. Z! w5 R, l4 { - Features::GeometricConstraintData::AutoConstraintTypeNone);8 t/ l" C; G2 M+ c' n
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);
8 q! O) P5 O: t" |( o - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);$ n' b4 i/ j" @6 K" ~: W. t! |! Y
- geometricConstraintData[ii]->SetCurvature(nullOffset);
6 K/ f1 }& W$ b4 s6 \1 u/ h. r - geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
" e* v+ e' |. ^1 v: T- h - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);: t* v5 U1 g; a/ M3 v3 D2 N
- }, ?/ c' ?3 R- Z4 I1 I" T Q/ g
& {* H- N0 v4 x& @; A0 v% x- studioSplineBuilder1->ConstraintManager()->SetContents(
6 U3 r' B. ~( e6 ` - geometricConstraintData);
* S# W: h% w0 ^' t; v8 s' T - ' W; ?8 W) \1 M) x
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
5 ]# U' x- N6 c) E, Y3 h9 v& Q( C8 R - Spline *theSpline = studioSplineBuilder1->Curve();
h; w' J" F( [
0 i- \. }0 m8 i5 H! }- studioSplineBuilder1->Destroy();
1 @7 |+ D& E; [" j
4 h( Q2 R& t$ z# o% n- return theSpline; ?& X( l+ C7 g: O
- }- [+ n( R) [4 z m' {
8 ]+ }8 A) u* B9 E( i3 ]- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
4 @! P- \! e4 [. s - {
' F% X, D% ]6 Q$ S - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");' L7 e( @ `9 I3 g" ?
- if (!thePoints.size()) return;6 e" ?6 A) x, @* C ~, ]6 Y
W2 K' m5 Z9 _5 F6 B- Spline *theSpline = createStudioSplineThruPoints(thePoints);
* m0 X* Q! ~1 Z - ) U- V+ i, s8 H+ F5 Q
- if (theSpline)
* {; ^4 I) B! J+ r: d+ z; D8 P - {- z5 ]& t& d8 S! P; t
- theSpline->Highlight();
: p% @; B9 |7 x# m - uc1601("Studio Spline Created Thru Points", TRUE);7 l# _" o7 t2 b6 n& f" P" U; h7 O
- theSpline->Unhighlight();2 R. U; `" n/ ]# q# {) O6 ~
- }
8 L4 @( F& w, U7 ^+ J& F - }; u$ r+ Q! R4 C& Y# L! y
复制代码
' G( l+ H) E/ ~0 p7 O9 W9 N+ T! F. j4 Q3 }
: ~4 ?. H& b5 [) v0 E' t, O0 t |
|