|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线
3 P/ Q3 w* G) d$ S; x% C- #include <uf_defs.h>
4 z4 @6 Y( R( o - #include <uf.h>
, f. A( i: H- |3 H - #include <uf_modl.h>4 X* a8 V( W6 ~9 _( i' e( b
- #include <uf_object_types.h>
: L4 G% b$ l3 K0 k8 s - #include <uf_ui.h>$ ]% B4 W6 n1 P. ~3 Z7 z6 J# E: \
- #include <uf_modl.h>8 t0 u& E2 P4 } h. n! [
- #include <NXOpen/NXException.hxx>( D7 j, b T4 y8 [) L; | G
- #include <NXOpen/Session.hxx>- g- c( @0 }/ j2 t9 [
- #include <NXOpen/Selection.hxx>, u% z4 r& j: } p, Y
- #include <NXOpen/Builder.hxx>5 j# @6 m4 v4 }: }
- #include <NXOpen/Features_Feature.hxx>) [% t7 g- ]8 I' e' g$ N1 m' v
- #include <NXOpen/Features_FeatureBuilder.hxx>
6 s1 X5 }% A; g2 I1 t* M3 S - #include <NXOpen/Features_FeatureCollection.hxx>
# `( c( j {2 G- ?" o - #include <NXOpen/Features_GeometricConstraintData.hxx>
4 w2 E1 i6 L, d5 R s - #include <NXOpen/Features_GeometricConstraintDataManager.hxx>/ R! ^2 b% ~7 |, Y! J5 @8 g
- #include <NXOpen/Features_StudioSplineBuilder.hxx>
+ m/ n7 |6 ]4 a( ]' H& M - #include <NXOpen/Part.hxx>
4 r {5 z& b' f5 y - #include <NXOpen/ParTCollection.hxx>
( P8 O8 C/ J+ x5 y& S/ l( o - #include <NXOpen/Point.hxx>
6 u" U! a ]5 _ - #include <NXOpen/PointCollection.hxx>
_. I# f+ ?/ s - #include <NXOpen/NXString.hxx>
8 U6 {5 n6 d/ A% F& \3 v3 j - #include <NXOpen/UI.hxx>& Z3 a7 }. _. @2 s
- #include <NXOpen/Spline.hxx>
; J0 z" S" t4 |5 O7 X - #include <NXOpen/NXObjectManager.hxx>/ e- n! t$ n2 j( l K3 G
* E5 x V1 s, q9 O6 J- using namespace NXOpen;
# q; p0 N& m7 r - using namespace std;
/ r( w" Q* i. F# o2 |2 D - , c V( F! S8 M5 I5 M1 z: D
- extern "C" DllExport int ufusr_ask_unload()
$ [0 u# `) Y( }, J Z' O+ z' Q' H9 A - {
3 F$ f! @- [4 R; S- ^ - return (int)Session::LibraryUnloadOptionImmediately;
$ j, Q2 m; m0 t) m% _' h# z0 U& K - }
! x: q8 l- R# I- s1 O - 1 X5 J R8 F+ Q- I+ P/ U" U% M
- static vector<Point *> selectPoints(NXString prompt)
5 u& l5 X. p' p. ~ - {
! C" Q" X& G0 {% w) n - UI *ui = UI::GetUI();
) s+ j! J7 x% b5 p$ v) s - Selection *sm = ui->SelectionManager();' g/ M+ b) z$ C7 O) S- e _
- std::vector<Selection::MaskTriple> mask(1);
2 w. Q f9 x5 ]- ~3 N8 G9 ]) z - mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
. z. T- _2 ]& |+ D v c$ A - std::vector<NXObject *> objects;
: D1 R0 U) z- y) U( D, m& I - 3 O# V, k( @1 D7 D2 q5 Q" f1 f1 ]
- sm->SelectObjects("Select Points", prompt,' D X3 [+ i; j0 B* d; b2 e
- Selection::SelectionScopeAnyInAssembly, u0 }6 Z% r# P; X5 T, F9 y
- Selection::SelectionActionClearAndEnableSpecific,; R, S5 B3 ~4 v3 h/ a0 N
- false, false, mask, objects);
3 T& K$ z' d$ J' {) G* Q# } - + o7 Q3 a. p) A( r D, V
- vector<Point *>selPoints(objects.size());( l# S: W: w( g/ X6 H& P8 z/ [; Q
- for (unsigned int ii = 0; ii < objects.size(); ii++). y) C4 Z9 y) A2 @& ]* {
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);6 |$ C* U- o: I
- + w& \2 w; r' H; J Z
- return selPoints;
2 U; H8 t! {& k' o$ d - } e/ |, l( T: h) `( r3 }/ l
I* r; n) Z7 y' a: J- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)( G; k% D3 ?- O1 \: W, H* |. N
- {- @# d2 i6 l( k. g; f
- Session *theSession = Session::GetSession();0 b# s, w. ~' _3 z* g
- Part *workPart(theSession->Parts()->Work());
1 B, d( |' G) z' B& ?3 \ - 3 N4 C* ?7 D) h4 W2 S2 R
- Session::UndoMarkId markId1;4 b: w1 M1 E/ [* J1 d
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,+ j3 {$ Q! g1 g* L; L) J. Q5 [
- "Studio Spline Thru Points");' q8 e- `$ a+ l
' q$ i A* K# \% u3 G- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
/ d3 S9 N) b7 v6 @
! T) t& @# y! H' q1 b, ` v- Features::StudioSplineBuilder *studioSplineBuilder1;3 k1 ?" I. p) ?$ L
- studioSplineBuilder1 = workPart->Features()->
" P1 |0 D T3 F* n7 ? - CreateStudioSplineBuilder(nullFeatures_StudioSpline);! A/ B5 n6 I. ~4 q; F+ v
- studioSplineBuilder1->SetAssociative(true);
4 i" a- Y( f2 m5 i+ ^$ g - studioSplineBuilder1->" Q! w! ?9 T8 Y( S/ _/ m: ~; j* x
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);2 I/ [ }, Q. L3 N1 C
- studioSplineBuilder1->
1 R, R* z& ]) ~6 v. v - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
~5 a# D% t2 f% c5 w0 e9 x# q - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
2 X9 q9 M. M" c- s - studioSplineBuilder1->SetPeriodic(false);
- N+ d: V. R8 F+ R2 f x - studioSplineBuilder1-> F5 G8 P! E2 R2 z& m
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);9 o7 E5 S( A- ]* y$ H# F& s$ z. j
- std::vector<double> knots1(0);0 a! f/ G5 p t4 U
- studioSplineBuilder1->SetKnots(knots1);
" {, F) } j& c4 s3 m9 [3 O - std::vector<double> parameters1(0);
9 P2 P* v; U) b+ z0 ~- \ - studioSplineBuilder1->SetParameters(parameters1);
* d& |! b* V( Z1 H0 a - Direction *nullDirection(NULL);
# N$ |6 |0 y5 @* {1 a. V4 _1 x/ q - Scalar *nullScalar(NULL);% Z- H7 Q2 z1 | x+ A! a6 M; |5 B
- Offset *nullOffset(NULL);
/ B3 `# }% y- Y - 3 R$ D# }6 A: H2 z$ R( S9 p* W3 a
- std::vector<Features::GeometricConstraintData *>: [" U) m/ N e! s
- geometricConstraintData(thePoints.size());$ c) \: b" P$ F% r5 w
- : g, p' ?6 e& d# n& I3 @6 _
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
6 [6 F' Q8 p# V6 N+ ` - {
C- f3 {4 U: ~% v5 i( F* G - geometricConstraintData[ii] = studioSplineBuilder1->
! m& H+ r' s+ Y9 e5 C$ q+ u! T7 L8 [& H - ConstraintManager()->CreateGeometricConstraintData();) o- z* |2 P5 v
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);
/ ^" i+ Z& o7 | - geometricConstraintData[ii]->SetAutomaticConstraintDirection(; n/ M5 n2 F" M9 }' L. \
- Features::GeometricConstraintData::ParameterDirectionIso);
- z* W+ [1 y0 h! g - geometricConstraintData[ii]->SetAutomaticConstraintType(
T& G) ?. T/ b8 m - Features::GeometricConstraintData::AutoConstraintTypeNone);5 p7 a3 I0 m$ H. v% j
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);6 g1 _# A" N( r* J# v7 A* Y
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);( O3 A, W2 @, Z/ K% V E( s! o
- geometricConstraintData[ii]->SetCurvature(nullOffset);
9 c; Y! K& y5 Z$ G2 g* x, p - geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);* `; s6 p( ]+ R% @0 M) R
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
7 E4 [. L6 x T3 @9 T+ P - }
9 K, {1 _) A- K0 u e5 ?
5 A' }( C n1 ^# ]) c3 ~) U' q- studioSplineBuilder1->ConstraintManager()->SetContents(
- _$ O, P3 C* {7 Q9 u6 R# | - geometricConstraintData);2 M$ `( X9 N- h( X! r- u
" D' v, O; s. u2 G" K2 ]- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature(); P2 H6 D9 H; I1 s# d
- Spline *theSpline = studioSplineBuilder1->Curve();
: C4 w" N/ G1 H+ \: g
% f* C7 A) b+ D6 O4 P: Y- studioSplineBuilder1->Destroy();( y5 N, x7 Z' C" ^% c, [2 k; q
- ' R& S4 f, v+ }+ u* u8 k7 ~7 u0 l
- return theSpline;
{" Z- D1 m8 F3 ^ - }
1 b" R5 ]% Q# R$ ^) b; k
' V. A3 h7 F" c9 Z, G4 j" J3 Z# W u- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
7 |; I: e7 J4 J) n - {
' d% @2 d. \2 \' G4 @- J2 U" v0 f - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
& ?, v: p- n; _3 k \+ ?! n& V, f! ^ - if (!thePoints.size()) return;
, A2 ]* L7 o, E) m2 N/ D" K
6 a0 |! I7 c3 `7 I) f0 c; U1 h5 b- Spline *theSpline = createStudioSplineThruPoints(thePoints);* j% J( \) A7 m/ e! s* N. r6 W' e
; T5 P; i. T) N9 l. F/ @4 t- if (theSpline)
- x" Q% V! \8 w% G. ~ - {
2 L! D- X$ |8 R6 B4 w, B2 e% |/ Y, u - theSpline->Highlight();% L' |6 V1 r9 q3 O( ~: P- v0 I
- uc1601("Studio Spline Created Thru Points", TRUE);8 n# x6 \+ O+ n; s7 w' U: z2 \
- theSpline->Unhighlight();3 O" ]* [9 o, p$ [. _6 F
- }$ e6 b9 R/ \) b% R' O7 o. z& r
- }( v s% ~, x! K$ y E
复制代码
3 \. t$ W( c) k2 N( G* T2 |
. I# {. @0 Q5 l: D9 P
: C+ f9 v0 p- S" x% @% }! u+ ^ |
|