|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线
1 z/ U3 ]2 g E- #include <uf_defs.h>3 C8 c! x$ L; c# ]) G
- #include <uf.h>% A8 ^6 n; J7 D4 ?6 _
- #include <uf_modl.h># T j. h& |7 Y6 q& Y0 T2 q
- #include <uf_object_types.h>
6 F- d6 e" H. Z/ z0 w4 P4 n+ ~ - #include <uf_ui.h>
, O8 g1 g* N. G, L% ~' d p1 b - #include <uf_modl.h>
' z3 _8 F5 t6 n+ ~& t4 u$ ?/ U - #include <NXOpen/NXException.hxx>
8 N6 u' r! W* R& T- z5 f! v - #include <NXOpen/Session.hxx>6 T% M# x; j' H) P2 g
- #include <NXOpen/Selection.hxx>
0 D3 l4 |+ d8 Y6 n( G; f: i$ C - #include <NXOpen/Builder.hxx>2 U4 J- y$ f+ j9 J. m
- #include <NXOpen/Features_Feature.hxx>
$ c- ?( ?( N' }6 c3 g. H - #include <NXOpen/Features_FeatureBuilder.hxx>
( {6 k: [5 {, ^3 ^) @# k" m( w- N - #include <NXOpen/Features_FeatureCollection.hxx>
" [; s9 l9 s& ?( ~ - #include <NXOpen/Features_GeometricConstraintData.hxx>
: b. J$ }2 f2 V) `; t$ [" G - #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
$ m- k- W8 ]) n% J' B - #include <NXOpen/Features_StudioSplineBuilder.hxx>
9 t3 E& g/ G' ?( ^8 H - #include <NXOpen/Part.hxx>6 L8 V1 v0 I+ B- S1 {' z
- #include <NXOpen/ParTCollection.hxx>
. \8 g/ n9 I- W# A2 s" q! S - #include <NXOpen/Point.hxx># i3 S0 l" {& b; B# E4 x6 k1 R7 z
- #include <NXOpen/PointCollection.hxx>. | y) r4 A+ K( Q& S6 F
- #include <NXOpen/NXString.hxx>% h: i0 [: N- A1 M$ [" z3 p
- #include <NXOpen/UI.hxx> O+ V; A f2 m0 {
- #include <NXOpen/Spline.hxx>* n3 \) `& P1 o) u# n
- #include <NXOpen/NXObjectManager.hxx>
) o) h8 | X2 r2 t" z
! I7 p. j0 s2 h$ b* k- using namespace NXOpen;7 X) R0 Z( N# y+ w+ U# C
- using namespace std;% G) E) h( v) U
- . S4 }( q8 `8 ^ s, ~' V
- extern "C" DllExport int ufusr_ask_unload()6 f, u9 C j5 A: h
- {, {5 o A8 D! E" C) P* o- {- N
- return (int)Session::LibraryUnloadOptionImmediately;& l5 t( e9 `/ q8 m
- }( ?0 j. v' Z: i/ x f1 v
/ X2 z4 E7 E3 s7 R$ i- static vector<Point *> selectPoints(NXString prompt)2 J8 e: ~, A9 Z8 j2 Z
- {. u& l; U" C4 y- T* G- ^6 ]
- UI *ui = UI::GetUI();
$ j3 s f5 ?7 O3 @7 q+ K - Selection *sm = ui->SelectionManager();) L6 n8 Q+ g' a9 U4 b: a( k( s
- std::vector<Selection::MaskTriple> mask(1);4 C0 y6 B6 V0 d( ^9 M
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);7 j' Q; R c3 C- j5 D
- std::vector<NXObject *> objects;
! O7 g! N4 q+ I2 ^) i+ p - * c1 h# P. q0 |& }# S6 F
- sm->SelectObjects("Select Points", prompt,
9 q8 @. ^8 t) |) H% R U - Selection::SelectionScopeAnyInAssembly,! B, O# ^: h: c
- Selection::SelectionActionClearAndEnableSpecific,% ?6 u) l: T C: l3 y6 P
- false, false, mask, objects);
. Y" F0 A2 R- S. c2 O8 Y8 l7 |# _
. w0 y8 s8 r, W6 c) L A- vector<Point *>selPoints(objects.size());0 n5 A) I1 {+ }( u5 ~; V* z
- for (unsigned int ii = 0; ii < objects.size(); ii++)
0 i# H. Q# t* `& f. L* W! i2 B3 j - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
+ ^4 b& O7 l4 N/ O6 C* x G7 @& `
; b O# q0 |3 F7 _8 V- return selPoints;
) v8 p& h! j$ u, Q5 R - }# v; g9 X1 V4 @/ ?9 i, N
; A" i# a: X2 A4 A. P" Q9 @. g( c- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
" x' a3 u- Y/ b - {
! _) Q& s, k8 |7 f, W - Session *theSession = Session::GetSession();
% O6 p- [( w H$ h5 v- j- A - Part *workPart(theSession->Parts()->Work());- C* X: D0 ~, c
- 6 Y/ F& j4 P; S* M* @+ y
- Session::UndoMarkId markId1;' m% x) L2 ~4 `; z9 q, [9 ]+ B
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,) g. z8 A$ q1 S' i$ {
- "Studio Spline Thru Points");- n; |; J7 Q* a; d3 W
! c# H" T: l7 J2 c2 Y2 T7 ?6 s- Features::StudioSpline *nullFeatures_StudioSpline(NULL);+ ~1 g5 ^9 }" E* K# r3 E2 t
- % \+ [; H f/ r: q4 I; Q. c9 @
- Features::StudioSplineBuilder *studioSplineBuilder1;4 i! ~! S4 @8 F; n! O K+ U
- studioSplineBuilder1 = workPart->Features()->
; i0 [3 \8 s- r" u - CreateStudioSplineBuilder(nullFeatures_StudioSpline);
; Z0 r. x Y) e - studioSplineBuilder1->SetAssociative(true);
* d* Y$ ~0 j. o, Z0 P6 @ - studioSplineBuilder1->
+ k+ H4 b1 d6 R7 t - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
0 e q- U! T; d - studioSplineBuilder1->
* G6 u- ]9 a; N4 L. R/ H5 u" y, i - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);0 B; @% z# t- P" b6 v/ W9 s
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
/ C) y4 E! A+ s2 H- L- a - studioSplineBuilder1->SetPeriodic(false);
0 C1 t) B9 b7 M, q7 c - studioSplineBuilder1->& u5 r) P' u/ w
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
- L; r$ d* H8 G9 o1 V% Q9 A% R - std::vector<double> knots1(0);: N( L. E' J* ?2 m5 p4 d5 c; l
- studioSplineBuilder1->SetKnots(knots1);* J" g: a1 Q7 |+ v: t: c
- std::vector<double> parameters1(0);: ?5 w/ q) z5 G3 ^3 m P/ Z
- studioSplineBuilder1->SetParameters(parameters1);
" _" `# u/ U* |$ n& s) ^ - Direction *nullDirection(NULL);
+ k: B! Q" M* K; P6 o9 Q - Scalar *nullScalar(NULL);
& _" l4 G# B" Y% @8 Z1 C - Offset *nullOffset(NULL);
1 x z; W7 U5 u( @% I# v- p - % G. N2 H* f" \! v( c4 m
- std::vector<Features::GeometricConstraintData *>2 [0 d z, i% t; v
- geometricConstraintData(thePoints.size());+ p/ g! F9 e% Q1 G/ R; X( l
# R( o" T: s" S* `- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
. ^" o, B, o+ O - {
3 a2 x3 s6 \3 M2 R8 X* u; q/ j6 m9 T+ A - geometricConstraintData[ii] = studioSplineBuilder1->
# @+ F9 a* [% t; Z& E; D: z, | - ConstraintManager()->CreateGeometricConstraintData();% H) k9 C) w5 p d# c9 b" a' V
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);
. I- L3 O+ a3 b9 _6 U - geometricConstraintData[ii]->SetAutomaticConstraintDirection(, u9 K! O5 Q, f0 P8 C0 P0 }
- Features::GeometricConstraintData::ParameterDirectionIso);
2 v; F6 R B3 v8 f- s* L8 R' R, u - geometricConstraintData[ii]->SetAutomaticConstraintType(* L R5 O2 ]% g3 A- ~
- Features::GeometricConstraintData::AutoConstraintTypeNone);
' v8 e, U$ d( u! ^! @$ ^ - geometricConstraintData[ii]->SetTangentDirection(nullDirection);' O; D- ?& T& p- R; t9 z# J g
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);/ O" b$ y. C% l. r2 {
- geometricConstraintData[ii]->SetCurvature(nullOffset);
5 s* A) y" R7 M/ x$ Y; \4 N9 D - geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
2 ?" U& u6 i/ ~, X8 @ - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
1 Q7 s9 E! x6 ]( |/ A1 Y- l8 T0 b - }) N4 v& m: ^/ u- i2 W) R
- ( U: z- A0 O6 S1 C0 q# g
- studioSplineBuilder1->ConstraintManager()->SetContents(' b' c2 i4 } f9 [
- geometricConstraintData);
, M7 a# m( U6 ]6 \ T/ M - 3 }2 x( n( Y: a( C
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
) Y* g! o; t, F; u - Spline *theSpline = studioSplineBuilder1->Curve();
7 w5 p+ K/ T! b, s& t9 H6 D
5 ?7 p8 W0 y( b* [6 s: h; T& ~9 M8 R- studioSplineBuilder1->Destroy();. _" L* s0 f( l. S( g
- + I! ~1 n: r+ B3 e( s# s* ~8 c: }
- return theSpline;
! X, {1 M. ^6 X& C, ^ - }
, ~9 \7 S8 a* o6 K! y; X - : b6 H4 o, G8 D
- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)8 \) x2 Z2 b6 q3 X
- {: n+ E$ H% j, M7 o/ o- h j* q
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");& a1 I4 x. O% g
- if (!thePoints.size()) return;
: ?% E: @) }% H0 }! Q% _0 x - 5 q2 s& d7 H, k1 h0 n0 x
- Spline *theSpline = createStudioSplineThruPoints(thePoints);9 L+ [1 h/ u, B* ?9 C2 |4 J
8 \, k2 b: k$ G# V- if (theSpline)
, w. b$ L3 w H! r( N! c: A1 Y - {
. t5 d6 X" Y/ T2 v* C - theSpline->Highlight();
y* P4 l* ?0 p' I - uc1601("Studio Spline Created Thru Points", TRUE);
) ]: L+ k2 E# n: X$ Y - theSpline->Unhighlight();
) @5 ]7 N# l( l9 H5 O9 I - }& L1 M4 F" g; E/ {+ u( C3 `1 z
- }$ k+ T$ M# c1 `
复制代码
5 \4 P" U5 B7 k1 C3 b' r) {* b
x7 i+ s8 }7 g" P/ W
0 X4 _9 ?1 `" j+ H8 o |
|