|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线" z0 a6 \7 M7 ]
- #include <uf_defs.h>8 l) ~# W* a- {
- #include <uf.h>) N3 `- d7 F) @! b) W! M
- #include <uf_modl.h>
- \ y1 G R" P7 ^% p- Q - #include <uf_object_types.h>! A$ h5 g; ]; l! m7 ?; @2 ^
- #include <uf_ui.h>: e& Q$ e9 K; Y+ v
- #include <uf_modl.h>% L; Z1 \: Z2 R: x
- #include <NXOpen/NXException.hxx>( U- W/ u- G3 @4 S3 H9 h4 J
- #include <NXOpen/Session.hxx>8 h7 O* Y; F8 b1 i% u2 n
- #include <NXOpen/Selection.hxx>
7 @6 l- S' C ^ {9 \. |0 q& Q1 s - #include <NXOpen/Builder.hxx>
6 i! F7 E8 a! j - #include <NXOpen/Features_Feature.hxx>+ b) V- @* ]! }5 j' j5 ?* x
- #include <NXOpen/Features_FeatureBuilder.hxx>0 l1 ?; {- J. K$ ^9 o- R
- #include <NXOpen/Features_FeatureCollection.hxx>8 u, E6 A% c) r
- #include <NXOpen/Features_GeometricConstraintData.hxx>
2 G8 k, p. Y/ `$ E* ~ - #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
7 z! q* U1 x ^7 Y1 m6 \ - #include <NXOpen/Features_StudioSplineBuilder.hxx>: j1 R% j; W9 s2 g2 ?! w
- #include <NXOpen/Part.hxx>' Y* v" {: f% Z
- #include <NXOpen/ParTCollection.hxx> X4 Y4 A1 c6 q- }! y
- #include <NXOpen/Point.hxx>2 n, e! _* a! U; ]: l
- #include <NXOpen/PointCollection.hxx>( x- `1 W7 k: G5 ~
- #include <NXOpen/NXString.hxx>' j/ s y6 W8 {1 z$ \
- #include <NXOpen/UI.hxx>2 W7 K2 g) ?. D) g
- #include <NXOpen/Spline.hxx># P) M. A e; T/ g) P% b" b
- #include <NXOpen/NXObjectManager.hxx>' Z! w3 J7 k9 [5 H0 |; M% b" V
- % g( o. c |8 Z$ T9 `% F+ D
- using namespace NXOpen;% U% J3 D0 z: A# S
- using namespace std;% v$ c8 R2 K# I7 O
- $ E* R+ s- Y1 I7 V
- extern "C" DllExport int ufusr_ask_unload()) H2 j0 P7 F( G) D- ]' j# i# i$ H
- {
8 H7 Y' e1 B- u - return (int)Session::LibraryUnloadOptionImmediately;
$ a0 ~: o p( K - }; B& w9 q) B7 o- \5 J
- & }( n7 K {7 @+ k; q2 T3 }
- static vector<Point *> selectPoints(NXString prompt)
. M/ f, c9 Z) u/ k% X% k W4 ~- i - {+ b2 a; Z ]& e7 q# i( w3 V
- UI *ui = UI::GetUI();
6 W. \/ F5 |! y6 P3 o3 J1 w$ J. T& w - Selection *sm = ui->SelectionManager();8 b, M, T) U! f4 V3 V
- std::vector<Selection::MaskTriple> mask(1);+ `0 d& P; Q* Z- F
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);4 c* y0 ^' r5 u1 S# @3 D6 w
- std::vector<NXObject *> objects;
1 q f" m5 w* r Q7 z% f' ~2 D
( C" [$ h, i1 M- F! P4 I3 i- sm->SelectObjects("Select Points", prompt,: `) E0 X' l- s
- Selection::SelectionScopeAnyInAssembly,1 `) |7 w! z# C4 i
- Selection::SelectionActionClearAndEnableSpecific,
; D, \* h# n% D% i- B! ~! R - false, false, mask, objects); e- a9 n2 v/ U6 b" T# j1 s, D
& K. ^4 q: z% l7 n: ]+ j- vector<Point *>selPoints(objects.size());% ]- g8 m/ x ~# x
- for (unsigned int ii = 0; ii < objects.size(); ii++)
' t6 {; x# }, z9 p+ c - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);; z- Q: ~* D# W
7 X5 _) X R" m" i- return selPoints;3 ~& l9 W" Z" g
- }
2 H5 R1 }0 x V$ [+ K9 U- I: n - " |( r, i. Y8 E j
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)0 }& f8 W9 u( V9 D( d: ^. @
- {
" G3 |7 W7 |' N! U - Session *theSession = Session::GetSession();2 |- W5 o9 I) }* z; Y, m
- Part *workPart(theSession->Parts()->Work());
+ h5 u& L+ a, E/ `9 ~( x7 R - ! e8 l0 n$ Z( @6 F2 R' k* y6 Y
- Session::UndoMarkId markId1;0 R2 [0 N5 [6 @. Q
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
( E$ f/ m$ \1 l% B3 Y, Y- j3 [ - "Studio Spline Thru Points");* ?1 r5 \) X/ g z& R4 R$ f0 N' @
# P1 h2 p! h) ?7 B8 g- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
/ \* {8 _ e* ^3 K Z
3 w4 Z# L$ b; Y( j- R- Features::StudioSplineBuilder *studioSplineBuilder1;
( j9 I& T1 D$ B- v0 j - studioSplineBuilder1 = workPart->Features()->
[) h4 G" K- G - CreateStudioSplineBuilder(nullFeatures_StudioSpline);
# R! O2 S% _9 B - studioSplineBuilder1->SetAssociative(true);
1 u3 o8 ]+ @/ [2 l6 r7 u- \ - studioSplineBuilder1->+ e: @* O) Q* r% `. O1 P& z
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
8 H6 \/ Z2 R3 i/ m" n2 V# } - studioSplineBuilder1->
/ h3 o; s. X5 }; ?0 ?- y# t+ { - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);9 T, w. e. ~! p0 m3 g; T
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);; d! F. \! _6 k/ Y: s, e0 Q; g
- studioSplineBuilder1->SetPeriodic(false);
{' T0 r6 z( M/ y. W5 D7 O$ { - studioSplineBuilder1->- B! A. O! I: f6 ~* \, W* i
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);: a$ ~. O( J$ ]' a+ ?( G" i/ W
- std::vector<double> knots1(0);- t" d1 M+ s8 t- Z" F% _7 J
- studioSplineBuilder1->SetKnots(knots1);
; @; J9 Z3 q" s* i - std::vector<double> parameters1(0);
5 r9 Y+ a+ }; D( o - studioSplineBuilder1->SetParameters(parameters1);
& D7 l" D) H1 ~# r" a - Direction *nullDirection(NULL);* X/ v5 i; ]8 ^- ~, ~7 n0 P
- Scalar *nullScalar(NULL);
8 B9 K% e* o0 w0 u- S3 t d, h" d - Offset *nullOffset(NULL);2 B; _- l8 q2 [5 K1 o: R
- 4 D1 z7 ~( ?; h' G
- std::vector<Features::GeometricConstraintData *>% h, K/ D1 f' H, b: T
- geometricConstraintData(thePoints.size());: c9 f2 u) f/ h7 c. z1 m6 v5 o% M
- ! P/ U* k9 W% S
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
F, U) O1 i3 g9 q; m - {' N7 k2 }2 s( b
- geometricConstraintData[ii] = studioSplineBuilder1->- U; g) N4 E, X5 x* g% s' {
- ConstraintManager()->CreateGeometricConstraintData();% ~! ^. h7 h6 C7 p! C
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);- A( p' A2 d+ Z& l4 |; ?
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(
j1 |4 S; D, E- B3 Z - Features::GeometricConstraintData::ParameterDirectionIso);, U' G4 D8 m3 \- [
- geometricConstraintData[ii]->SetAutomaticConstraintType(5 H8 @" x+ q, s+ l1 [
- Features::GeometricConstraintData::AutoConstraintTypeNone);
/ D( \4 x$ u" K4 s) \ - geometricConstraintData[ii]->SetTangentDirection(nullDirection);
9 S( R# Z' d! [/ N+ p+ i$ ?" G, r - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);5 M, l, n0 o$ K. [
- geometricConstraintData[ii]->SetCurvature(nullOffset);
2 d8 U* u! [" p7 Q: C - geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);5 F' E% f5 U x7 A" G
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);3 {9 Y6 J, o6 ]/ T
- }) _& q# R8 `( w: y
, L+ P! X) ^3 }4 A2 F7 Q- studioSplineBuilder1->ConstraintManager()->SetContents(3 d& f. L! O" S2 K/ `+ `
- geometricConstraintData);
3 Z: R8 F4 u1 @ |0 Q3 G" A
l% u5 A5 t U& Z/ ]- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
0 G. D; ?0 N" q+ T0 K! n9 B - Spline *theSpline = studioSplineBuilder1->Curve();
1 |, }- m9 |" I" e
* r8 h( d1 v+ M. f' _ p- studioSplineBuilder1->Destroy();/ q7 n' {% W- l. ^! [$ d0 K- V2 N
- ( @% i/ Z/ l% T0 ~9 ^' U# ~
- return theSpline;
8 K4 y- ^6 \5 `- | - }$ y( ~: d$ t3 x3 v2 w
! e0 ~+ A0 i c! v6 C5 e- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
, }2 S9 k, M$ [8 a% U* m) \* k - {
* P3 B( l$ ]# p - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
9 ? j- w v. `# g* S - if (!thePoints.size()) return;
5 ^' c* [" ?8 s! l
8 U1 L1 L. [8 H w; M Y5 {- Spline *theSpline = createStudioSplineThruPoints(thePoints);
! y: g# o2 W% S: m
6 Y, }8 M. X/ B5 ^/ K6 C3 q- if (theSpline)
3 W- M- T& v: h8 w% @! S - {
8 p* |1 N2 V7 w- t - theSpline->Highlight();& p- z9 ]& _4 l' b5 k- {. i( Q
- uc1601("Studio Spline Created Thru Points", TRUE);
" h) C7 s$ O. L - theSpline->Unhighlight();
% R Q$ X3 {: ], \ - }
' ?# i" Z* g$ b - }$ v% c+ r: }4 d& b& X2 O8 W
复制代码 ' b0 a3 I5 |9 ]( n. h
% P/ ^7 M+ q) _/ z
1 }! c! n0 v# N* q1 D( A! X |
|