|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线
" J! Z% o6 Q3 M3 Q' o( U- #include <uf_defs.h>
0 H7 M' E+ j/ b# M" ~ - #include <uf.h>
' o2 `( H3 e$ A - #include <uf_modl.h>5 \! v" d5 |* d/ E, l0 s2 s4 A- K7 f8 R
- #include <uf_object_types.h># E% M: ` V' G, c& x3 s9 b: F
- #include <uf_ui.h>
% T! d Y( L! F9 k# g" Y# B* B - #include <uf_modl.h>6 ]4 W, S2 B% S6 y" Z$ i
- #include <NXOpen/NXException.hxx>/ T5 X; o% i+ a& x% Q
- #include <NXOpen/Session.hxx>7 I- `3 C5 z$ O5 x1 |2 d( `% Z& J
- #include <NXOpen/Selection.hxx>
. l3 W1 j2 J8 v! @& w - #include <NXOpen/Builder.hxx>6 `! x( ?0 L) e5 C9 e( h$ H8 u
- #include <NXOpen/Features_Feature.hxx>& R! A% P+ ?- @/ O
- #include <NXOpen/Features_FeatureBuilder.hxx>
* o& a7 e* u5 m& Y5 M - #include <NXOpen/Features_FeatureCollection.hxx>
- P5 C0 n- y* _3 | - #include <NXOpen/Features_GeometricConstraintData.hxx>
% i& ?% _; }0 E6 {7 s - #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
% d! V/ e* u2 X' K* V' g) I - #include <NXOpen/Features_StudioSplineBuilder.hxx>% X' E$ d$ G) R, m$ N) P; a
- #include <NXOpen/Part.hxx>
$ \" T; _' m# O! E% X - #include <NXOpen/ParTCollection.hxx>- O' p2 O% A% o* ]8 A1 \& S* t& ]
- #include <NXOpen/Point.hxx># k# ]* _+ ?: e3 z' m
- #include <NXOpen/PointCollection.hxx>
7 g" E! _. T# j: u: y' [ t' h - #include <NXOpen/NXString.hxx>
0 g3 l$ N- \8 r8 [! k - #include <NXOpen/UI.hxx>( O9 O, {5 [! _" d: C- j5 R. c
- #include <NXOpen/Spline.hxx>6 Q# ?) ?: |( p. H) m, s$ |
- #include <NXOpen/NXObjectManager.hxx>3 e9 `& m. a# g5 ~% V0 N" H
9 Z7 M& S( V' J5 n- @- using namespace NXOpen;
# C% Q% o4 L4 o" X, K3 j1 d0 K - using namespace std;
) O) y. z8 ?+ I# s# e. e2 m9 @
- t6 {, v0 Z# x+ n" j% r2 p/ K9 K# ^% I- extern "C" DllExport int ufusr_ask_unload()
" u3 P$ f! D: C - {# j2 X2 j) j2 ~
- return (int)Session::LibraryUnloadOptionImmediately;
8 H, D2 Z$ d: G/ K" X! f1 ^6 ~ - }
' y. _" z, z' i - 2 j- M9 s0 [. _0 c
- static vector<Point *> selectPoints(NXString prompt)- x5 `* |7 e) P9 e' A: P. B
- {
4 s9 K2 [" ~8 B+ k. \% d - UI *ui = UI::GetUI();- A/ g+ Y3 e& K5 x
- Selection *sm = ui->SelectionManager();
* S, y4 ~5 m2 A8 o1 S - std::vector<Selection::MaskTriple> mask(1);
0 F& J. i8 L# U3 @ - mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
/ f: u1 ]& ~$ \! }0 [ Q0 D - std::vector<NXObject *> objects;
G' F+ z" U; _$ d6 [' a- ]
. H/ J2 H1 f. E1 l4 r- sm->SelectObjects("Select Points", prompt,
$ Q. d% {' ^* B3 Q - Selection::SelectionScopeAnyInAssembly,# G% m; S; q; Z) V# J
- Selection::SelectionActionClearAndEnableSpecific,
. m, p. |' C2 n" N5 }6 G. | - false, false, mask, objects);- @% m: S4 ~1 a' c* {! x
- N, B; \* W( ^7 I* w
- vector<Point *>selPoints(objects.size());
# Q! J' `- H! d+ g* ~ - for (unsigned int ii = 0; ii < objects.size(); ii++)
( [8 R* L* q* [( X, W! m - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);: l) ^" d5 ~6 ^, ?0 e8 i/ |$ \
6 U$ K n8 V+ g$ }- return selPoints;
; B) g& _+ t) d/ @5 {( O( Z - }+ }0 l" G4 G8 V) L) C3 Y
- . E, a3 T3 X, T' J* H
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
0 u# v. o6 H/ S) d - {' h' n. f" y( C/ G- [9 S
- Session *theSession = Session::GetSession();
9 Z' ` a; g' H* }9 n3 g - Part *workPart(theSession->Parts()->Work());! C& ~8 I* j$ b" A5 `/ k: {8 @- Z
- 2 q3 J, e" v6 P7 u) _+ A9 Y
- Session::UndoMarkId markId1;
; C" P4 y. G, j5 Z8 A1 ^2 t - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
8 V$ v7 Q" n8 A4 m$ x - "Studio Spline Thru Points");
% ~, z* o7 z, a8 P9 h, L - 6 X; H% |: B" f5 v: ?/ z% _
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);7 V |7 D5 g" G9 ~/ M
- $ _' Q; h: D! s2 d3 i7 ?( e
- Features::StudioSplineBuilder *studioSplineBuilder1;- |. {2 p( l2 h' C+ L5 O( u" W
- studioSplineBuilder1 = workPart->Features()->
' s5 u+ I; w; M - CreateStudioSplineBuilder(nullFeatures_StudioSpline);
/ q# \- p6 L- a3 O4 E% Y H$ { - studioSplineBuilder1->SetAssociative(true);
! X1 N5 y; g2 I; m4 M1 y - studioSplineBuilder1->; ~1 S/ c# Q0 ^8 G
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);+ J5 d8 a+ ^! K, i8 H |* q
- studioSplineBuilder1->$ t: Z$ G { D, {
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints); i2 Q. G7 W1 Q+ k. R
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);% \' M# _ z2 B- }* c
- studioSplineBuilder1->SetPeriodic(false);) ?' P! T' U! ?! j# t* K
- studioSplineBuilder1->; m0 G8 [" a4 E# r
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
?8 s2 h+ n% I* w2 z' s - std::vector<double> knots1(0);" h- F* O* J0 q3 L
- studioSplineBuilder1->SetKnots(knots1);; c# `0 K1 L8 Z& W
- std::vector<double> parameters1(0);; n4 c- y* C( ]! b/ Q5 I
- studioSplineBuilder1->SetParameters(parameters1);8 Z/ g4 b) T9 n0 Z# I
- Direction *nullDirection(NULL);
$ B9 D8 t! g# w _ - Scalar *nullScalar(NULL);) l; e4 \4 {4 R \
- Offset *nullOffset(NULL);4 r6 ], I8 y: X- P( ~' J y
5 g, ~6 K( U7 x$ b$ `. Y- std::vector<Features::GeometricConstraintData *>2 I# {! e2 c- [4 ^/ D
- geometricConstraintData(thePoints.size());1 C4 M* E2 i. c7 \
- - S! \" M$ i# }6 q3 @
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)& f9 j* T. T6 ~# b
- {6 c' E) }# K) t+ ?# n* ]
- geometricConstraintData[ii] = studioSplineBuilder1->8 j1 ^8 y1 |% F+ }6 y. h$ v
- ConstraintManager()->CreateGeometricConstraintData();/ U o6 @, ?7 U$ e+ n
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);1 _ r; n5 Z7 }) U. H" ?% h% f+ u
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(2 E4 n0 ~3 @- c+ J* U% M% u! N
- Features::GeometricConstraintData::ParameterDirectionIso);
% A$ X. S2 i0 R; S2 [0 W - geometricConstraintData[ii]->SetAutomaticConstraintType(. |- O, S$ g. k; {6 G/ ?: y; o
- Features::GeometricConstraintData::AutoConstraintTypeNone);8 a" J2 H3 U. j! |; C6 f
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);# ^4 ?5 `# d+ Z' o, I/ C
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
" o. _- O# K# t2 h2 T& l2 p7 |, B - geometricConstraintData[ii]->SetCurvature(nullOffset);* x% b) ?% O: ?- ? J$ I, f$ X
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
+ r: u0 y& L* R+ p1 [ - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);- W' @& C; n9 g* G( c6 X
- }
2 B3 X" R# D+ Y$ w' u - + q) Y7 V( I) K2 \
- studioSplineBuilder1->ConstraintManager()->SetContents(
E3 b j) K8 E5 w - geometricConstraintData);6 X& `" d( m; L6 d- H& g, ?
( ^( b P- C5 ]+ x8 x- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
d( y$ R6 N" S) C% H - Spline *theSpline = studioSplineBuilder1->Curve();8 O. R' P. |* C5 k5 e! G3 i
0 y4 P9 A7 n8 C6 q! G- studioSplineBuilder1->Destroy();
7 x: j( {: e* j: v7 ^ - % i7 h- ]( L1 {! Z
- return theSpline;' J' i' h1 G* u( t3 [9 o
- }( @3 N8 ]1 v; b+ p F
+ G; w3 l9 G/ N0 H- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
1 g1 h3 b+ }' H5 E: m - {
% r' z6 h+ V+ {- G. R; a - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
& E% j8 G: `1 | O - if (!thePoints.size()) return;
6 d' }4 C# F3 e+ F - : y, [% y4 ?5 h& ~$ }
- Spline *theSpline = createStudioSplineThruPoints(thePoints);
% X1 {% `" a1 [ L# {/ [ - 8 w% y, P( H' ]2 X, K; r
- if (theSpline)1 w7 ^ D) |0 d& _5 \( w# c
- {+ }9 G7 a9 _ q: X2 q
- theSpline->Highlight();
% n1 B- U: G( |8 P4 |, d - uc1601("Studio Spline Created Thru Points", TRUE);
& Y" ?2 i4 |4 {) l( V - theSpline->Unhighlight();
0 o$ E- n( N- Q( V6 n( A) u# n - }3 g' ?* h" E4 e( L% v
- }
Z; X/ k( R; k1 f4 ?
复制代码 ! L' x9 f& f, Z
+ B0 S3 Z/ `" ~4 L `. P' b" L
4 K0 \1 p! L3 O+ p! @ t f
|
|