|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线9 R; p1 I3 Y8 z7 ]( _
- #include <uf_defs.h>
# Y2 ^. P; ]) T k _1 U - #include <uf.h>
+ U6 W0 `7 t" \$ j; k% s - #include <uf_modl.h>& C, M! P: {: x& D
- #include <uf_object_types.h>
# P! Z" {0 C* ^! K - #include <uf_ui.h>
+ A8 c5 s! J' h9 \8 b* D1 M - #include <uf_modl.h>1 h/ o2 }# {( k( F0 \
- #include <NXOpen/NXException.hxx>
: O2 c6 w& h. _# D9 t6 Z$ ]7 Z - #include <NXOpen/Session.hxx>
2 U( i% k5 I. j) d- q' p - #include <NXOpen/Selection.hxx>. g0 y. ~, k3 R1 I M& ]! D; ^
- #include <NXOpen/Builder.hxx>
& {( f; x+ ~' F0 A6 |3 W - #include <NXOpen/Features_Feature.hxx>
: @& w3 z4 N; ^ U* M/ q6 t - #include <NXOpen/Features_FeatureBuilder.hxx>
0 t1 [2 d: e3 k/ J+ c4 O" G2 [ - #include <NXOpen/Features_FeatureCollection.hxx>
8 Z: }* M B6 N' \8 Z7 v - #include <NXOpen/Features_GeometricConstraintData.hxx>! T; w5 R- F" p( {" o7 ?. C, @
- #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
3 F b) H# ~3 W2 } N- o) j6 z - #include <NXOpen/Features_StudioSplineBuilder.hxx>
" {- ]8 l: f! X; E v/ o - #include <NXOpen/Part.hxx>
7 J2 Y# A; P4 W" D. i: q1 o9 j - #include <NXOpen/ParTCollection.hxx>9 G0 A# j- Z. C: a" X# g6 _
- #include <NXOpen/Point.hxx>
7 Q6 S6 z0 n) V9 q8 m. \ - #include <NXOpen/PointCollection.hxx>, o3 u) {+ B0 j
- #include <NXOpen/NXString.hxx>$ ]" E, K8 H7 `' F3 k7 ?
- #include <NXOpen/UI.hxx>
) C! J# h9 v; [ - #include <NXOpen/Spline.hxx>
( c8 m. F" A! R. z - #include <NXOpen/NXObjectManager.hxx>$ I: K |9 F% v3 u/ A, S
- P$ L' p8 T) }0 j
- using namespace NXOpen;
" x/ ]% J4 n; w$ i: q - using namespace std;
( |+ h- M- a/ C' B+ _ - 5 E7 i9 R+ ]8 H
- extern "C" DllExport int ufusr_ask_unload()
3 `9 N; C. y/ ~; b7 ?0 b - {0 a) s- j7 X1 @1 S
- return (int)Session::LibraryUnloadOptionImmediately;2 I) e! a. |- x/ r- l6 ?" x+ [
- }5 ~6 X6 K% h' A5 ^3 k, C
' K- x0 ^( N5 i' ~/ q5 K- static vector<Point *> selectPoints(NXString prompt)
8 z, J3 H% c% G s- M& E; k* p q& _ - {
5 }; d& l* j# P6 | - UI *ui = UI::GetUI();
6 N5 y6 n" [) w6 B - Selection *sm = ui->SelectionManager();
7 N6 }2 H U% t% k - std::vector<Selection::MaskTriple> mask(1);: M* N0 F. c% @8 {$ S1 M3 o
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);- z5 d8 s. _. W$ q/ x3 e
- std::vector<NXObject *> objects;
& k0 Y0 O' m6 S/ z - - \; h9 b. m; O, |
- sm->SelectObjects("Select Points", prompt,3 V5 h# N" g8 d/ P" G7 \
- Selection::SelectionScopeAnyInAssembly,, w3 y/ s! K" S0 U$ I# g H! R
- Selection::SelectionActionClearAndEnableSpecific,# h/ W+ l, k$ c2 a8 n! ?% b8 e
- false, false, mask, objects);6 O$ y/ C+ X) F) O2 E
+ k1 n' M2 r- p& j; w% q- vector<Point *>selPoints(objects.size());
8 K4 F/ S0 }9 p1 u( l - for (unsigned int ii = 0; ii < objects.size(); ii++)
9 b1 B8 Z0 }1 @/ _ - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
! F" T3 Z1 H S - / d1 y, S; O; h9 U% J% a9 J
- return selPoints;0 z" W# u- I; l! `+ G2 Q5 F. A
- }
; j) x e9 q6 n3 ^: L - 5 ~. g# u0 F" ^
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
( Z7 Y& |* q# }# s) i( m7 O) O - {
3 h9 W; h7 \9 j1 M; \" \8 u - Session *theSession = Session::GetSession();
3 W: y3 X$ u! d) g1 e - Part *workPart(theSession->Parts()->Work()); q4 C4 E h' {
1 u. e7 X) R# g4 f& [7 \! G; b1 Z- Session::UndoMarkId markId1;- B. e5 h: I7 F8 ~# l; e! U
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,- E# c+ K3 g2 K3 \# d
- "Studio Spline Thru Points");, l" b, W2 ^6 c" }
- ' V; ~- Q+ A4 P6 f/ n4 d5 e; [
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);# G- L! z/ ~3 {
- 3 F$ k" \9 I8 c8 j% Z3 i7 r
- Features::StudioSplineBuilder *studioSplineBuilder1;
7 J$ B' j6 T: z1 P - studioSplineBuilder1 = workPart->Features()->
2 Z) z+ d' w7 `4 V) F- k - CreateStudioSplineBuilder(nullFeatures_StudioSpline);; @6 k8 L0 A5 h# d, W4 y6 X4 S; f
- studioSplineBuilder1->SetAssociative(true);' ^, ]1 R; B! A# y4 U- ]% O
- studioSplineBuilder1->
0 z: r$ a6 Q0 K+ f7 j5 A& M7 v - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
+ L/ ^9 F! L; E, D3 X - studioSplineBuilder1->$ S; V6 J0 K: V, V; n, p
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
& s* S5 m$ l0 z0 l - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);, P% l9 _8 h$ R
- studioSplineBuilder1->SetPeriodic(false);
( K' _7 J) I, x! o; O0 A4 J3 w - studioSplineBuilder1->2 y9 g( e7 V) @; O6 _; Q% ]8 m+ F
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);3 w- L& f* o8 F
- std::vector<double> knots1(0);
: X, w7 d' j9 S0 Z, y - studioSplineBuilder1->SetKnots(knots1);
`" _4 C1 ^, s+ C; M' O - std::vector<double> parameters1(0);
' i* g, W! V6 p) t) q - studioSplineBuilder1->SetParameters(parameters1);4 y" Q+ W* [7 F; X/ Y: B, U
- Direction *nullDirection(NULL);
5 d/ t0 W4 n& T: l$ A - Scalar *nullScalar(NULL);
/ p W Y; S) F3 H - Offset *nullOffset(NULL);
4 J( k9 u& P$ v! ?$ A
/ p& p1 e& V: J" n- W; Q7 P5 E- std::vector<Features::GeometricConstraintData *>9 F* J( c2 [9 x& f- r$ m
- geometricConstraintData(thePoints.size());, `$ T2 p6 O$ p& x
% B0 i/ I, o$ C1 w Z$ J$ j2 q- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
! i4 _* J- E* n0 o- b - {( T+ Y) M; q# p$ Z- ~6 Q0 C
- geometricConstraintData[ii] = studioSplineBuilder1->7 u( [: `5 }9 Z5 ~2 s5 j9 _
- ConstraintManager()->CreateGeometricConstraintData();
4 a/ l" D3 h/ I( y - geometricConstraintData[ii]->SetPoint(thePoints[ii]);
5 r9 i7 h1 ]2 x - geometricConstraintData[ii]->SetAutomaticConstraintDirection(3 A2 J* ?! C. L3 C
- Features::GeometricConstraintData::ParameterDirectionIso);
$ C P! R# ]& K7 {) V: e - geometricConstraintData[ii]->SetAutomaticConstraintType(
9 f) O3 o* K- j - Features::GeometricConstraintData::AutoConstraintTypeNone);
5 t& y4 A6 ^" F8 [% ?" N$ O5 H B - geometricConstraintData[ii]->SetTangentDirection(nullDirection);
: u$ A, L6 Y' C - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
7 c( \2 u) u1 o% a% r - geometricConstraintData[ii]->SetCurvature(nullOffset);
1 n/ t2 h# `/ a: V3 M/ G* r: v - geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);' o( _& J9 q& t6 g p' h
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);" ?3 W; C, U2 E* T
- }5 e9 m+ Z9 z6 d. X" d7 R5 {9 [
- , y5 E1 j3 y$ F; G# @; s
- studioSplineBuilder1->ConstraintManager()->SetContents(
& }: B4 w6 F9 m" S& V - geometricConstraintData);
2 B) C' H4 i+ e5 k" g
* w2 x9 D/ S( k8 s9 T- r- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();6 ~" V5 s; J4 z ^* L" W- O
- Spline *theSpline = studioSplineBuilder1->Curve();
! z, `6 w ^. l( x* S - % j2 ^2 p9 K/ _0 z1 e! d; o
- studioSplineBuilder1->Destroy();
: X. D$ v/ i! E3 C7 k q
( L( x, P& y; t+ x# R) R- return theSpline;9 `: \8 a6 ~. H
- }# b9 {8 V2 B* F% X" z
- , O% S, \, R7 `" e) k/ u3 [
- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
# v) F' j2 X; ?. h- N# B+ E N: J - {
7 K& D- e& M; l; T- {1 A - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");2 n' @3 K% F, L
- if (!thePoints.size()) return;
4 _, A3 N3 J1 h6 g1 `' h, l3 a/ j
% |# [2 B: {5 m- P- Spline *theSpline = createStudioSplineThruPoints(thePoints);" b) G5 E, f [9 L" [% h# q9 P: K
- 5 E5 `3 O x1 @- z( L. B3 L6 K1 y# y
- if (theSpline)/ }" N5 F- p1 G; m: Q" @
- {* }" D$ s5 _# X) S
- theSpline->Highlight();* ~+ R0 r! @( Y7 r5 i. T; l
- uc1601("Studio Spline Created Thru Points", TRUE);
# m3 ?; n) R: T$ b( J) x$ } - theSpline->Unhighlight();+ R3 e4 b3 M+ A. n! t7 G- i w
- }# G7 z- ]8 V: C7 t+ l a
- }5 o6 m5 g) M& O' [4 y$ P4 Q
复制代码 2 |% a4 W) j. ?: G! J
" I1 A( ~9 ^: G+ P" W0 y+ S" c1 U
# Q6 F; j" v9 r" e |
|