|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线
5 _# j. k" P( P- #include <uf_defs.h>
. ^& u! J; U0 t$ Q+ L; U - #include <uf.h>
: L9 s1 ~% [) l1 R! { - #include <uf_modl.h>
b8 ]4 [/ q- Z; ` U% R1 ^ - #include <uf_object_types.h>
, Z' ^8 A/ l! @+ X, j* m6 i - #include <uf_ui.h>
O0 M. t' @0 `4 ? - #include <uf_modl.h>3 @& `* T8 j5 r2 S* a: G' k& K
- #include <NXOpen/NXException.hxx>
# \) ^" {* ]. J, }5 ]' k' J - #include <NXOpen/Session.hxx>. c! z% `1 w: C" k
- #include <NXOpen/Selection.hxx>
# c2 n( Y* }7 i' n& _ - #include <NXOpen/Builder.hxx>
6 ?& W2 t# n* d7 ` X - #include <NXOpen/Features_Feature.hxx> l) Y. w% x o) V8 O
- #include <NXOpen/Features_FeatureBuilder.hxx>9 C0 g2 g/ x0 E
- #include <NXOpen/Features_FeatureCollection.hxx>
3 g/ M/ [ Y8 r - #include <NXOpen/Features_GeometricConstraintData.hxx>
& i! J; v( H; O - #include <NXOpen/Features_GeometricConstraintDataManager.hxx>- ?7 |* [7 t' y, G2 g
- #include <NXOpen/Features_StudioSplineBuilder.hxx>4 ~( i8 X" s; A0 k8 Y, E+ g
- #include <NXOpen/Part.hxx>( T6 R/ R9 R% N8 H2 u' v z) _
- #include <NXOpen/ParTCollection.hxx>
3 n' I7 G- a% M5 z5 ? - #include <NXOpen/Point.hxx>
% j' D. O( `# e - #include <NXOpen/PointCollection.hxx>6 n$ Y6 l4 `6 O% s; F; }( u
- #include <NXOpen/NXString.hxx>
/ C& E: M6 k) I - #include <NXOpen/UI.hxx>7 C" W# F: `/ e
- #include <NXOpen/Spline.hxx>& c$ }9 c/ R/ C7 R
- #include <NXOpen/NXObjectManager.hxx>
: _5 X# K( [8 x/ ~ - . k& I/ q) W! n$ C2 Y" X; }$ A1 C
- using namespace NXOpen;
$ U& B& @' A1 o3 F) o' Y - using namespace std;* @0 ], D8 y6 S1 D* S: h! R9 n C
- 3 i* J- f, X4 i" T7 [
- extern "C" DllExport int ufusr_ask_unload()
5 D/ Y. Z% G+ b2 [( r - {) v, ^1 y2 S$ H8 F& n; Z* j
- return (int)Session::LibraryUnloadOptionImmediately;
9 ^3 T% ^; n! r" L! f) s3 o - }
- P1 M+ c$ O' }" E. } - 3 D; M' N8 f6 R% k( z6 [
- static vector<Point *> selectPoints(NXString prompt)7 j( J* Z+ h: o( \1 I! x% R
- {, s) D# v8 ^2 d4 _
- UI *ui = UI::GetUI();* {( T: N4 ]8 E. t- [$ N9 o# j
- Selection *sm = ui->SelectionManager();
0 z5 n9 Q& M# ^$ P6 R. G9 Z! t - std::vector<Selection::MaskTriple> mask(1);
- ^( n" ~5 X# j& K# H* z9 _7 G5 n - mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);7 P0 v3 d8 P2 x
- std::vector<NXObject *> objects;% f7 ~' X, h+ ~( B) A
7 s( O0 _- i$ \. Q2 N- sm->SelectObjects("Select Points", prompt,) u3 k' m1 p& p0 t1 O
- Selection::SelectionScopeAnyInAssembly,
. t3 H0 m4 o; v* A - Selection::SelectionActionClearAndEnableSpecific,; ?1 m0 B7 W9 u$ p, x
- false, false, mask, objects);" D/ k2 p6 h; C7 U
- - r3 W7 {. v* W$ p" ^
- vector<Point *>selPoints(objects.size());
9 D! o" `$ N; H, m) b - for (unsigned int ii = 0; ii < objects.size(); ii++)3 X5 p* S1 m" {% L
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);+ s5 g% w1 R1 i1 u G
) s! R+ q4 Z' T4 w! X- return selPoints;
7 C5 ?" |$ o5 N) U - }, ~$ k, i% F, B. ]" T6 S6 T
- , I5 r4 P1 h8 ~ ^# e1 Z/ Z
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
7 l8 m% r& R Q: A - {
0 A. {3 u8 a! x9 l* F - Session *theSession = Session::GetSession();- l8 _; l) @+ P
- Part *workPart(theSession->Parts()->Work());. P0 J: e6 l( ^+ s6 U
- 1 C" z1 G7 D% d& K
- Session::UndoMarkId markId1;
1 u0 Q* t6 D9 G - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,+ n9 ?# r, A }' [- `1 R4 n# q
- "Studio Spline Thru Points");1 Q2 h% O* C8 M$ ]+ O# |
- i; s' b- i: I4 a
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
% z3 C, E/ p" @2 `# o. W
4 N# Y" R6 z1 y0 A- Features::StudioSplineBuilder *studioSplineBuilder1;! s" P7 C& t3 o. o
- studioSplineBuilder1 = workPart->Features()->
$ B. B. T% z& g t$ j( D( v - CreateStudioSplineBuilder(nullFeatures_StudioSpline);
1 P$ R+ m: E) ^8 O - studioSplineBuilder1->SetAssociative(true);
8 D, s5 m! S+ G ]- r( v) u) R - studioSplineBuilder1->+ ^$ M7 Q- j) x
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
5 h: o- C) |3 D) h$ h( e% t - studioSplineBuilder1->% i, v6 n- U0 e! B6 t( f( F
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
4 ~, `: f& z) W) U0 m5 Z4 a! d - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);( _" c* N$ m5 b. ?3 V' j8 d+ L
- studioSplineBuilder1->SetPeriodic(false);* H7 C4 o7 y) }$ I2 S
- studioSplineBuilder1->; J3 Q* w: v! H7 `0 O
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);2 d5 W% G4 G! P; r
- std::vector<double> knots1(0);
& g" s, W$ F6 _7 V) S# N9 i i6 C - studioSplineBuilder1->SetKnots(knots1);' W2 Y6 E1 ?' d$ j+ g
- std::vector<double> parameters1(0);! l9 [0 r( @& A8 w
- studioSplineBuilder1->SetParameters(parameters1);/ W: ^' ]' ]- t% X7 R. p# t. Z" r
- Direction *nullDirection(NULL);
1 z/ G, @) w! s4 \" U - Scalar *nullScalar(NULL);
1 O1 F: N, X8 g( v% T$ ?9 Z - Offset *nullOffset(NULL);* C$ G+ k3 B* E/ w* M/ C$ U$ A. A
- & h) r. `* H7 A4 i$ Y
- std::vector<Features::GeometricConstraintData *>; V8 X$ J: c8 h; f, t, N0 M
- geometricConstraintData(thePoints.size());
2 b5 d; o) B0 ?1 m: Y, E" V( [0 \
1 f- q- M9 M# \! R2 @! ~- ~5 D- for (unsigned int ii = 0; ii < thePoints.size(); ii++)+ W$ ~% ]7 U5 D D: g6 w+ |2 w
- {
! V* l+ Z4 V, N& p2 @& o" | - geometricConstraintData[ii] = studioSplineBuilder1->* g0 |: Q& A1 J" F/ I
- ConstraintManager()->CreateGeometricConstraintData();8 Z/ _- Z. `" r5 Y7 a' R) s5 S8 @
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);8 ~6 `+ x: P' S# `) X5 S
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(1 C, k) O4 v8 @3 g& j/ B6 g
- Features::GeometricConstraintData::ParameterDirectionIso);9 M8 I% ^5 c, ? Y
- geometricConstraintData[ii]->SetAutomaticConstraintType(
6 F& B3 Y! Q% b/ k/ X' ]6 \7 Q - Features::GeometricConstraintData::AutoConstraintTypeNone);* d8 ^- k9 [( G$ Y1 _
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);/ d) Z* A$ e5 ~' h/ L' k
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);! x% ~0 {4 ^( F1 U* {/ M% @
- geometricConstraintData[ii]->SetCurvature(nullOffset); T4 H- @. q4 n, e8 F' ]# `
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
2 Z9 L. Z; M' j, v0 m% C - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
$ Y6 Q8 J6 P' y( b0 k0 R& L3 F3 P - }
; t4 J8 B" ~: G6 F1 s$ n - # T. U9 U% ]! |* ~, f! v: m
- studioSplineBuilder1->ConstraintManager()->SetContents(
8 G7 [: p3 c: H$ }7 z" ]2 f5 w1 P+ S - geometricConstraintData);
8 u2 o5 e4 S+ S% U! O/ p/ a - 8 g4 @1 Y, O: `5 `) F
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();- y8 j: p e! H5 ^7 S5 O2 u
- Spline *theSpline = studioSplineBuilder1->Curve();2 C) v) P0 g7 P9 @2 n: R- a" | l
6 j3 U4 T0 S$ \! e# `- studioSplineBuilder1->Destroy();1 M' G* R1 O) v+ J- h2 G n
1 d# p: w1 h1 g- return theSpline;9 h$ o7 @( M, f4 Y
- }$ j0 B1 C4 S$ j2 A' X1 ]
- ( I3 F' z3 t1 R: w2 x
- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len); m( t; P3 m/ y0 w; ^
- {: H# ~ N( A6 I) T5 j/ N# `. A
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
% y2 X T+ i7 C2 s - if (!thePoints.size()) return;
( t8 t& T1 \1 T8 [4 {3 ^- L
6 I2 N- o8 r- F' e5 q% {- Spline *theSpline = createStudioSplineThruPoints(thePoints);: O$ C! b" F" z! c2 H
* n( Y" w( W- s- if (theSpline)
/ L; m. e; Z0 S$ \# s: Y - {
8 J/ b# t& |- h- }4 P! m - theSpline->Highlight();" n6 \' F3 F# @, J& X( E+ z; ?1 Q! T
- uc1601("Studio Spline Created Thru Points", TRUE);
# n3 v2 v4 ]: H0 f. X' _ - theSpline->Unhighlight();
# L2 k K5 K( q - } M2 Z* h0 [: Q, `, s! a5 R: D
- }
5 ]" ^ i, R: J+ t
复制代码
9 \% ~/ D9 _; d
( X9 D( M) Y) o: x, l2 n. U5 R2 w
|
|