|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
7 q0 `4 B8 Q# C/ A. CNX二次开发源码:通过选择点创建样条曲线
% W( s G9 D( u7 f
& f( P/ e+ T& k$ G" h& U) A* d, J) f; I8 |4 _2 U- T9 Z6 a7 e
- 1 q# M T# e4 S2 m8 ]8 P. M
- #include <uf_defs.h>
G5 {, v( n3 [# p+ E - #include <uf.h>
% Q$ I5 Y" H6 j% F - #include <uf_modl.h>' x! C; r, _% w5 c: E
- #include <uf_object_types.h> p' k) T' _* g
- #include <uf_ui.h>
4 ?7 y B; o3 k7 p- s - #include <uf_modl.h>
$ i E! a9 P8 f - #include <<em>NXOpen</em>/NXException.hxx>
4 I# D \" ~* F6 J+ y; V - #include <<em>NXOpen</em>/Session.hxx>
0 i; s" L: Z1 }' S/ t0 w - #include <<em>NXOpen</em>/Selection.hxx>* U, P5 A {% p+ [; M# `) D
- #include <<em>NXOpen</em>/Builder.hxx>& _$ o2 B+ X) a0 `
- #include <<em>NXOpen</em>/Features_Feature.hxx>3 v. p1 i1 R/ t$ J9 a$ w
- #include <<em>NXOpen</em>/Features_FeatureBuilder.hxx>
+ J3 V Z, w- ^: q& U3 | - #include <<em>NXOpen</em>/Features_FeatureCollection.hxx>
+ E3 n2 M! C- J0 F3 D - #include <<em>NXOpen</em>/Features_GeometricConstraintData.hxx>& x2 |, ]) v8 T l, I8 A
- #include <<em>NXOpen</em>/Features_GeometricConstraintDataManager.hxx>
; S& {: m5 }! a - #include <<em>NXOpen</em>/Features_StudioSplineBuilder.hxx>
) w7 r7 p( L8 A" ]7 R6 n& r0 l - #include <<em>NXOpen</em>/Part.hxx>
6 v8 \- H2 s8 h - #include <<em>NXOpen</em>/ParTCollection.hxx>
8 b. r+ u6 {% q' H; E - #include <<em>NXOpen</em>/Point.hxx>: R( I% ?; K: v' w1 `- E) m
- #include <<em>NXOpen</em>/PointCollection.hxx>
- u" T+ T) d* n/ P/ f/ ] - #include <<em>NXOpen</em>/NXString.hxx>
0 S" d( W6 w) J, W+ ?, k - #include <<em>NXOpen</em>/UI.hxx>
- I1 }" E) W: A8 Q% J9 l. f - #include <<em>NXOpen</em>/Spline.hxx>
7 n$ C# D7 {2 @/ |5 R - #include <<em>NXOpen</em>/NXObjectManager.hxx>
' Z9 w+ f! q, M4 V& K5 F9 T8 f - ; M }8 J& i- j
- using namespace <em>NXOpen</em>;
4 n0 G7 }9 O7 ]( n/ B - using namespace std;8 }. n) H( Z' i% E
- ! z8 h; U+ ]2 L& N( Q; |
- extern "<em>C</em>" DllExport int ufusr_ask_unload()4 a" g" D& |/ t2 \% u
- {
, Q6 F- V. r: n/ z, B6 S$ X2 J5 D - return (int)Session::LibraryUnloadOptionImmediately;* R R. Y* O1 d0 s! \7 f
- }
9 i/ ^( E8 R8 G0 `; C( \" M, S - ) u' c M5 f( U. V2 g+ u
- static vector<Point *> selectPoints(NXString prompt)( ~) B9 |9 i6 ^2 P) ~& F$ E
- {
% G- R3 t7 O5 y0 n* _9 I2 f8 g - UI *ui = UI::GetUI();' E C, H& r- @; J
- Selection *sm = ui->SelectionManager();
9 {5 P1 f- Y& {* l0 d - std::vector<Selection::MaskTriple> mask(1);! ?0 G8 L1 s- U5 [5 C$ x
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);+ A3 U% m' s# F
- std::vector<NXObject *> objects;; g# ]7 z0 ?6 Y6 j+ X6 s
X1 A* y' c# H4 V# X+ S+ ~' `- C- sm->SelectObjects("Select Points", prompt,
- v/ H# @: F) f8 x* t - Selection::SelectionScopeAnyInAssembly,7 h, o; u! r: d9 b
- Selection::SelectionActionClearAndEnableSpecific,$ ]- ]) W: |7 V8 l8 ^- f* D/ b. a
- false, false, mask, objects);
; Q! h& ]9 O+ d6 {6 k
s; U$ @/ H. ~) ?, T. j- vector<Point *>selPoints(objects.size());
- k; w+ a* m3 w) S5 W - for (unsigned int ii = 0; ii < objects.size(); ii++)1 V9 R6 w/ @2 w; _; K$ I- C# J c+ Z
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
! e1 o. e7 h* o2 y* E
$ @: C3 X& U5 z% F, ^: N1 M/ T- return selPoints;0 `% R* W& K" z* Q$ `, D9 A- ]: k
- }! p6 b* @1 H( J- x+ {0 J; H. J: m
( b4 B: ^9 s/ T1 A, _: |" D- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
2 w& \& i2 W/ H - {
8 J5 R% ?* \: m4 D3 X8 w - Session *theSession = Session::GetSession();
& _* i2 p$ d, B6 e5 V - Part *workPart(theSession->Parts()->Work());
& f" C g! P/ R/ G! a1 m
" Y/ q+ _( {3 M- Session::UndoMarkId markId1;, u$ g1 ^0 N& h" G' R! b; ?
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
; X) _" u! W9 a% ~: T8 @+ K - "Studio Spline Thru Points");; b y1 K- T f5 C; D0 X
- ( T' [3 x, n3 L3 c
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);8 g' v) t+ Z; m) o' W5 D& S
- " I7 Z8 O* Q" q( _# C% ^
- Features::StudioSplineBuilder *studioSplineBuilder1;
f/ l9 A1 Y3 f+ H! P - studioSplineBuilder1 = workPart->Features()->. _+ e1 \$ S3 p/ U- p, J7 |
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);0 f; P; @' I3 R: \( Y
- studioSplineBuilder1->SetAssociative(true);4 G U$ c/ |3 i! V: ?
- studioSplineBuilder1-> Y) `- l* f* {
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
0 l* V2 S; N- e2 d: @ - studioSplineBuilder1->
- Q! } ~/ a5 f - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
! V. ~2 E7 Z1 P5 E/ M7 ? - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);% H b# ?% p# {6 q. g+ n
- studioSplineBuilder1->SetPeriodic(false);2 \9 Y' N) [5 e2 K Z0 U. _- [
- studioSplineBuilder1->
6 J; \3 s: }; b6 R - SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
0 r. o4 O' K7 z n& H - std::vector<double> knots1(0);8 J: A' g; P5 x+ Z
- studioSplineBuilder1->SetKnots(knots1);
& f7 f2 \3 R& l6 P3 U$ {. V - std::vector<double> parameters1(0);: V9 V$ P" _% j) t
- studioSplineBuilder1->SetParameters(parameters1);: A! t* ^. k8 j# n
- Direction *nullDirection(NULL);" E! E7 b4 ^' ]0 T! D) z
- Scalar *nullScalar(NULL);7 n& Q/ D, p5 b( y- M$ F |! {/ P& ?
- Offset *nullOffset(NULL);4 W+ W5 d- D3 g$ l% P$ T6 u
7 Y0 Z) x% S5 X9 x; C- std::vector<Features::GeometricConstraintData *>' K* I S% e3 B! Z4 m7 D
- geometricConstraintData(thePoints.size());7 w* ^8 r+ F. Z! j, |) |
- ( ~7 c% j' E. F3 }! E; v/ j( S8 q$ {
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)8 z% {5 g4 T3 i9 I& Q$ [
- {
1 S P& S3 ^7 V) e - geometricConstraintData[ii] = studioSplineBuilder1->) Y( ~& }1 `9 B
- ConstraintManager()->CreateGeometricConstraintData();
" K) X5 Q; l/ [ - geometricConstraintData[ii]->SetPoint(thePoints[ii]);
/ T4 K' J8 s" A! b3 r9 B - geometricConstraintData[ii]->SetAutomaticConstraintDirection(
6 u. J3 Y; v) r - Features::GeometricConstraintData::ParameterDirectionIso);
/ a2 G/ r" ^% r& S6 _ - geometricConstraintData[ii]->SetAutomaticConstraintType(
( ~& ~0 H y* c - Features::GeometricConstraintData::AutoConstraintTypeNone);3 [4 u3 ^& c4 D. ]6 `9 t- a
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);
' [$ q& z0 ~0 g* }* v. N _% a) c - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);! D3 ~5 u- k# P6 N
- geometricConstraintData[ii]->SetCurvature(nullOffset);+ i& |7 W4 h6 \9 ~1 n* ?' \
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
/ _7 |& N" a: m - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
. a2 v, |6 }) N4 K" V+ Y* f - }
6 y; ~1 o7 A& p' [
0 O- V: N- d9 T6 s! [1 K6 H- studioSplineBuilder1->ConstraintManager()->SetContents(
3 L/ h5 u/ Y, g" f o/ ?! F - geometricConstraintData);0 y6 ^$ H3 n5 o) \1 }
- ) z8 S$ G2 c& r* b, g, f+ D
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();0 z" g& S. Z. j: x F/ |0 Z: Q
- Spline *theSpline = studioSplineBuilder1-><em>Curve</em>();; |0 n2 ]* G7 f h x& d
- - V% @+ q9 C I2 v) @
- studioSplineBuilder1->Destroy();
+ p$ l: b( @1 g# s
! ~- J: |3 t% e8 u! y0 _! I _- return theSpline;6 s' {2 v0 U9 X% L" N7 B% u* a
- }1 ]7 C3 K5 E O5 N# A. l
- % D% }6 d- N" K5 \& ^4 g& n, N. D
- extern "<em>C</em>" DllExport void ufusr(char *param, int *retcod, int param_len)* Y; P% j( q+ K. u3 ?- y
- {
* f0 B; [% Q# K% ]+ z$ Z% A - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");$ E3 k6 _2 O, J& J# _
- if (!thePoints.size()) return;8 D8 ~# q7 G _- A! ]# S7 e% ^/ E" s
4 z/ k8 x+ O! r, I# J& l: N- Spline *theSpline = createStudioSplineThruPoints(thePoints);
% d) @* W3 w! y6 o& U) d) a - ) f+ |; v6 `( r. }) d2 W
- if (theSpline)
$ m% e7 l8 v& q" k7 ^1 s - {( ^9 V# u5 \7 N& m& ~, n. b
- theSpline->Highlight();
) b4 A- l' a! X7 ` - uc1601("Studio Spline Created Thru Points", TRUE);& u1 w2 c( i; m1 H) S
- theSpline->Unhighlight();
, r, N* M' P& ^% v- R5 D - }9 \, @' [: n7 h1 k5 c
- }
7 E' f9 y& X! H - <p> </p>
复制代码
. ?! F. T, u4 S6 s3 A. p2 S+ v2 } |
|