|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线
; `( n4 O F6 s3 j/ O- #include <uf_defs.h>
7 E% [+ e/ v, l! }6 P) f9 i - #include <uf.h>
( @; F @9 D$ G$ u - #include <uf_modl.h>. U; Q+ Y! s5 U( E( x% m% b
- #include <uf_object_types.h>1 T6 ?, ?4 I: W* D5 K" M. J% y
- #include <uf_ui.h>
" W9 v# L5 t2 L2 f* J: a - #include <uf_modl.h>/ D, ]/ V, ~* ]$ H2 Y0 I# ^
- #include <NXOpen/NXException.hxx>5 I. e" K3 O( d4 y
- #include <NXOpen/Session.hxx>$ d) W/ Z8 t, S8 \9 t
- #include <NXOpen/Selection.hxx>0 F$ E2 Q/ ^9 m; e- |9 ^
- #include <NXOpen/Builder.hxx>* L, G5 T! s" T" W& L1 ^* V* |9 a2 S/ v5 i
- #include <NXOpen/Features_Feature.hxx>
" S5 \* I6 X ^9 O4 S - #include <NXOpen/Features_FeatureBuilder.hxx>
7 I6 I: B# {8 b7 Q& y5 u7 D! ?7 M - #include <NXOpen/Features_FeatureCollection.hxx>2 e, E% i$ l! }
- #include <NXOpen/Features_GeometricConstraintData.hxx>8 b4 C" j n5 a; K
- #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
4 Q8 L' j1 @$ d - #include <NXOpen/Features_StudioSplineBuilder.hxx>
5 S! Z- m; @% O% O. _; d7 y/ u - #include <NXOpen/Part.hxx>
$ t3 @5 i" V! q - #include <NXOpen/ParTCollection.hxx>
1 V9 X% T. x h [. c5 I$ d2 F - #include <NXOpen/Point.hxx>$ O! i+ ?, X) R% h
- #include <NXOpen/PointCollection.hxx>
9 a4 B" G5 G( v% e* X - #include <NXOpen/NXString.hxx>( V3 p$ k' }1 {2 I
- #include <NXOpen/UI.hxx>: m: u- x) I) I! S. W
- #include <NXOpen/Spline.hxx>
' ~0 H# B9 r, h9 O$ Z5 q - #include <NXOpen/NXObjectManager.hxx>2 A* o2 s3 v6 K Z/ y% K
: x. O, j+ m; X8 c/ }6 N- using namespace NXOpen;5 E& O4 h+ Z2 V" z4 ]& a V6 d
- using namespace std;2 x4 l+ m; t. d. A- ^( R5 d
- $ x5 {9 G7 W3 k/ H) F
- extern "C" DllExport int ufusr_ask_unload()
- J/ g, Y. F* a" h; B* p - {
; m2 r. c' O E# x6 E+ V- D - return (int)Session::LibraryUnloadOptionImmediately;( Q% D) b: }2 B7 {
- }3 C( a& C6 t3 g& {1 D( W$ g* N/ H4 e
9 e! C+ t a0 c8 i( v t- static vector<Point *> selectPoints(NXString prompt)
: j' ?+ h3 A1 f" @" r/ o+ o( |! q - {
6 Z& d. L6 E7 ~9 a4 {' W - UI *ui = UI::GetUI();. m& L& J& U$ b' L$ r- r& _+ v
- Selection *sm = ui->SelectionManager();
2 S# M% d b X; H5 w; i3 O' Y - std::vector<Selection::MaskTriple> mask(1);
/ t7 M: [) @0 G - mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);& ~ i4 Q8 L, H. m7 j( U7 N# W; ]
- std::vector<NXObject *> objects;
- j0 j+ t9 X- g$ q/ f
7 T0 c% b" a- B3 ?# t" e7 h9 m+ h- sm->SelectObjects("Select Points", prompt,- |/ F- H+ [ {2 F
- Selection::SelectionScopeAnyInAssembly,
* O+ X7 K' o& o$ a- { - Selection::SelectionActionClearAndEnableSpecific,& ~. K+ t' F8 a) L8 H+ x: ]/ O
- false, false, mask, objects);
0 j$ }8 d; T8 S9 k5 {# M - : j" {4 K- m* H; R; ?/ h
- vector<Point *>selPoints(objects.size());
! c5 V/ U8 Z0 K, r - for (unsigned int ii = 0; ii < objects.size(); ii++)
/ t4 S6 m$ p4 _1 Q" L' e+ y6 { - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);. U' F+ g6 z$ H( P# S; ]
' ^9 S# B$ V2 O3 ~6 d/ X7 I+ W- return selPoints;6 @/ V. a% c$ o6 W- u
- }
* C2 T9 X" o, F& e1 c
5 c' Z* N2 j" v# z6 j, B0 |- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
/ _9 e4 V7 c0 u! p - {( k. M! V/ c$ O X5 z8 _
- Session *theSession = Session::GetSession();
4 ?" v4 n# Z6 F) j - Part *workPart(theSession->Parts()->Work());: v) s! l% q- R# D- O. O
- 5 P6 w# P& K! _& j* b+ @
- Session::UndoMarkId markId1;
" C# D" E9 t6 M8 l - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
9 B/ a; y& _: q/ N1 ^% G# L - "Studio Spline Thru Points");* O+ p; f7 I7 s
4 ^# ]; e+ r' G2 @- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
+ \( |* c/ y; u; @# e: h+ j
4 C0 X; Z# N* S! t- Features::StudioSplineBuilder *studioSplineBuilder1;
b. ^' _& k r+ ^ L$ s8 i3 B - studioSplineBuilder1 = workPart->Features()->
. C9 ^% l9 _ I/ R# y - CreateStudioSplineBuilder(nullFeatures_StudioSpline);' G. ~9 P! S2 j6 ?/ Z5 h* u
- studioSplineBuilder1->SetAssociative(true);! C' E/ X! K7 u
- studioSplineBuilder1->5 ^$ B; E9 }! H: @7 `& h+ a7 i/ x* v
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);: U% T- w* u% v' i8 T3 W
- studioSplineBuilder1->! \4 _3 ?# q0 D
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);* A: w" l4 ^5 q! x) h
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);$ X, l9 _3 S8 q
- studioSplineBuilder1->SetPeriodic(false);8 ~' d2 Y: @* M4 A4 ^3 J
- studioSplineBuilder1->1 e* H7 i4 E# A& N* E8 `
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
* D! S' u7 I2 S. n6 H - std::vector<double> knots1(0);
4 a5 Z$ U- {2 S- U0 b; Q- t; P5 ^ - studioSplineBuilder1->SetKnots(knots1);5 m- h( w& W! k% M* R( N+ }
- std::vector<double> parameters1(0);1 m5 H$ k: v* \& l! \3 W+ k2 ]0 y
- studioSplineBuilder1->SetParameters(parameters1);: y3 t M- s) }; {6 M4 N& U
- Direction *nullDirection(NULL);
$ |6 S& d1 @ R* H% o7 n0 h# l - Scalar *nullScalar(NULL);$ u$ K! d8 \; d$ Z g6 V, g! }% K
- Offset *nullOffset(NULL);
' l! R2 W3 Z! y6 g- R/ F$ u( `
9 V9 d/ ~. @8 A H }7 {7 O9 {- std::vector<Features::GeometricConstraintData *>
0 T9 @2 X+ y$ B# Q9 T: e - geometricConstraintData(thePoints.size());; H! Z4 {5 y0 h% R
p S6 G- r! \" A, p6 J- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
$ K2 Y0 G; ^. F - {
5 J' d7 ~0 \. ?0 M4 S( M - geometricConstraintData[ii] = studioSplineBuilder1->
9 r/ f2 o& Q# l. o. e - ConstraintManager()->CreateGeometricConstraintData();
4 f; {7 {! c+ x8 U) R# s - geometricConstraintData[ii]->SetPoint(thePoints[ii]);6 { X% m* ?8 D5 q( K9 x- a
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(: h) m& Q- ?) A, H
- Features::GeometricConstraintData::ParameterDirectionIso);
% M- ?9 {2 e% a& k8 f+ K$ I) c' | - geometricConstraintData[ii]->SetAutomaticConstraintType(. p# x1 s/ O( ]
- Features::GeometricConstraintData::AutoConstraintTypeNone);5 D. Q% {" K1 x! ~6 [* i1 B
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);
! @$ }" z' _- T( { - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
) e0 }7 i9 t0 T0 m0 r7 Z6 y - geometricConstraintData[ii]->SetCurvature(nullOffset);
( U$ [* t* q* c8 x3 S9 f3 G$ O# s- c* j - geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
7 S- u X ]$ p$ f4 _ - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);$ s* n: `$ Q2 c$ K8 i
- }$ y- Y" |, a8 d4 Z8 _0 \
- ( p. L" B; q$ C6 u$ Y; D' w
- studioSplineBuilder1->ConstraintManager()->SetContents(( `- j! ~) o7 A! l/ D7 ~- O& j
- geometricConstraintData);) }& Z" U1 w& {- ~4 p1 n) v2 S+ A
- # b! [7 o) E3 Z) `8 E' O
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();- o% K$ ^: K) R7 |& |. S
- Spline *theSpline = studioSplineBuilder1->Curve();
# v7 i0 T8 Q8 M9 @+ N" U - : S0 _ z: i+ {6 e8 Z% p# y
- studioSplineBuilder1->Destroy();1 M P0 h a3 L2 L6 Y( R8 i; [6 h! v
- 7 [- T( V- [2 i9 m0 N1 W
- return theSpline;
+ R* G# K( N6 B( Q& l$ F8 C; ? - }7 J, c; u' V/ u
- ! ]! \" ]1 e. U( n! d, a
- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
6 \5 ?) u1 Y. R' H! i/ t3 r - {
5 u, h1 {% r6 T5 L: T - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
6 q( |. z! j5 Q3 Q9 F, C - if (!thePoints.size()) return;$ D e; x* N3 V" @6 F' e4 N7 V; s3 X
0 N& D& c, n+ y# m* O7 p- Spline *theSpline = createStudioSplineThruPoints(thePoints);
, [1 k6 I1 V# w+ p6 k5 k. O- Z& I
' N. Q3 E7 @3 v2 o0 [ U- if (theSpline). w* e) f1 f' j+ C0 \
- {
* X. M$ K! G; ^. u0 P+ S - theSpline->Highlight();
p w" {+ G& j - uc1601("Studio Spline Created Thru Points", TRUE);
) J. R% U8 O7 R' o# r# g - theSpline->Unhighlight();
2 Q) z5 _# f" J - }/ E, G* e2 _) G N. a3 D
- }7 T1 K9 a" F! l! S+ l# B+ v
复制代码
6 n2 s! f2 y; e' i2 K! l
/ d1 `/ D7 z5 V4 o* n$ H# C" |7 J4 q
|
|