PLM之家PLMHome-国产软件践行者

[二次开发源码] NX二次开发源码:通过选择点创建样条曲线

[复制链接]

2013-12-11 11:14:40 3356 0

mildcat 发表于 2013-12-11 11:14:40 |阅读模式

mildcat 楼主

2013-12-11 11:14:40

请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!

您需要 登录 才可以下载或查看,没有账号?注册

x
3 e& t' i: c: i/ x
NX二次开发源码:通过选择点创建样条曲线
$ ?: w' v' f4 e* x" W; D, @6 h* L# `* \& o2 X2 [
* r+ o/ w  |, H/ @& R

  1. . b/ \3 n% y2 T
  2. #include <uf_defs.h>+ B1 `! a% m( R. z" N1 z
  3. #include <uf.h>
    # C& J8 u6 e* Y6 o8 }5 I2 c
  4. #include <uf_modl.h>' ^0 u. K. D! Z! a# G( B
  5. #include <uf_object_types.h>6 N" j0 _) p, Q. T0 V6 x4 c/ \+ v) j
  6. #include <uf_ui.h>
    0 Z2 E+ L% j7 p/ O. `
  7. #include <uf_modl.h>9 j. S4 a% C! P# U
  8. #include <<em>NXOpen</em>/NXException.hxx>
    5 L* j! m4 m5 k8 R4 v! V1 D
  9. #include <<em>NXOpen</em>/Session.hxx>: h( s1 S/ C9 q1 {5 w
  10. #include <<em>NXOpen</em>/Selection.hxx>
    5 H9 c! O0 k5 M$ L% V
  11. #include <<em>NXOpen</em>/Builder.hxx>0 M, L, [1 `) |% h2 \, G
  12. #include <<em>NXOpen</em>/Features_Feature.hxx>
    4 y* Q+ }: x$ u
  13. #include <<em>NXOpen</em>/Features_FeatureBuilder.hxx>) z- U+ B1 V4 v2 r
  14. #include <<em>NXOpen</em>/Features_FeatureCollection.hxx>) T& k) C$ q% Q& K. u
  15. #include <<em>NXOpen</em>/Features_GeometricConstraintData.hxx>& U( I* ~9 I' K* F; A3 ~+ P
  16. #include <<em>NXOpen</em>/Features_GeometricConstraintDataManager.hxx>
    8 ]6 _# v1 U5 }( ]
  17. #include <<em>NXOpen</em>/Features_StudioSplineBuilder.hxx>+ s; {+ r+ D" g
  18. #include <<em>NXOpen</em>/Part.hxx>! i0 z/ |) R; s) T8 a) J
  19. #include <<em>NXOpen</em>/ParTCollection.hxx>
      r) b* z8 \% L
  20. #include <<em>NXOpen</em>/Point.hxx>$ b4 d1 j" j2 l( D$ J' l
  21. #include <<em>NXOpen</em>/PointCollection.hxx># P4 S" E2 z- U. W3 `6 `% k
  22. #include <<em>NXOpen</em>/NXString.hxx>
    3 A9 \( R; p8 O
  23. #include <<em>NXOpen</em>/UI.hxx>
    : o& u4 |+ ?5 I/ H; m0 D1 q
  24. #include <<em>NXOpen</em>/Spline.hxx>
    % {% g( e6 [9 A. y( m  Z( ~
  25. #include <<em>NXOpen</em>/NXObjectManager.hxx>
    & t& v0 Q7 `9 ~1 E3 i

  26. : `& l' ~7 S$ `' o! ~9 }
  27. using namespace <em>NXOpen</em>;
    3 _0 t5 x+ Y! u0 L/ p% D. s* ^7 f3 |3 y
  28. using namespace std;
    ( M4 x/ Z3 O: W6 A
  29. # k/ ^( H$ ~5 O# m1 B/ F
  30. extern "<em>C</em>" DllExport int ufusr_ask_unload()
    % N7 _3 x* i; K9 ^3 C7 L9 Z
  31. {
    ; a6 [$ ~# |: V8 W
  32.     return (int)Session::LibraryUnloadOptionImmediately;
    , R! V, i' c$ X; `
  33. }- A( C: L! e3 t4 G
  34. 8 Q# @- g1 w9 o) J
  35. static vector<Point *> selectPoints(NXString prompt)
    : A! B1 i6 L# V% b( x9 O( c
  36. {
    6 c& ?6 g& ?! n4 r% e
  37.     UI *ui = UI::GetUI();8 s( k2 c3 Y: n- {5 Y7 b* c
  38.     Selection *sm = ui->SelectionManager();' k1 |* @6 \7 p
  39.     std::vector<Selection::MaskTriple> mask(1);, q: t0 O" C( g2 }% \+ ?$ A
  40.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
    2 a! {7 c; j6 |* \* X. ~2 {0 R
  41.     std::vector<NXObject *> objects;  E+ S. t, ?' V$ j+ g; `
  42. . u  A+ Y  i" ~1 R3 [) J+ k- e
  43.     sm->SelectObjects("Select Points", prompt,
    7 U$ S8 Z0 R  m9 y3 G( D  s: c
  44.         Selection::SelectionScopeAnyInAssembly,
    7 d# @  u: y: i9 ?2 B% U3 k
  45.         Selection::SelectionActionClearAndEnableSpecific,
    0 ^, z% M4 ^& A( C* I7 x
  46.         false, false, mask, objects);
    + T3 ]* ~/ a) `3 \
  47. 4 e$ I; d7 F6 w: n4 S3 p
  48.     vector<Point *>selPoints(objects.size());  P, l6 [* x& P
  49.     for (unsigned int ii = 0; ii < objects.size(); ii++)
    - f! x1 N3 X  l. x4 o8 F- m
  50.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    ; a3 Y2 L$ K3 o8 D
  51. * A6 \+ X' S: ^# J8 x
  52.     return selPoints;  n9 j8 Z2 k1 y6 }
  53. }
    5 {9 H# V# p  Y; v! @; N/ r

  54. 0 w4 x4 {/ g$ H- f2 p; u/ S% C) X* q
  55. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    2 U' U% B( E* d
  56. {7 \; |1 s3 H  \, B
  57.     Session *theSession = Session::GetSession();" F7 H* G9 G, R" f3 _
  58.     Part *workPart(theSession->Parts()->Work());
    $ L3 x% t" k8 x0 B" o  F
  59. . U/ t$ ?$ R( w$ H' l) t! q! v  w
  60.     Session::UndoMarkId markId1;
    2 m4 o, O% A& X
  61.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,7 L* `5 @! |$ v- ^
  62.         "Studio Spline Thru Points");
    8 O/ `0 R4 \* B+ T" ^4 g; ]
  63. / A& u1 p0 G# o. p& l
  64.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);, D( l: S- R1 _% S

  65. " N# {0 E" \  z- S4 d
  66.     Features::StudioSplineBuilder *studioSplineBuilder1;
    & _- Z2 e0 L" _5 j
  67.     studioSplineBuilder1 = workPart->Features()->: z( w0 F( U" J+ E. p( A6 C
  68.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);' M1 {9 g$ Y8 b8 n) L. }5 I
  69.     studioSplineBuilder1->SetAssociative(true);1 }% M6 s  E' H$ k8 G9 q. L
  70.     studioSplineBuilder1->
    : `0 Y+ P3 V/ {1 d$ X$ w
  71.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);6 D# D, j! C; z( E& n& F& Q
  72.     studioSplineBuilder1->
    $ S+ Q: `1 i+ t  \  t' |
  73.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    1 s$ V+ T  q) I$ E) u$ I3 K
  74.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);+ h/ J! |7 o8 F: o) j
  75.     studioSplineBuilder1->SetPeriodic(false);9 H5 |0 V7 Q2 ]( q! p. }5 x
  76.     studioSplineBuilder1->
    / D8 G- P% T) V1 s, \2 u
  77.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    8 r  E* d/ h6 W; u* I2 a2 M2 z
  78.     std::vector<double> knots1(0);" w# @# ]# T0 q# u% G5 o* N, g  m
  79.     studioSplineBuilder1->SetKnots(knots1);  r5 s; K5 t* W: H5 H) z
  80.     std::vector<double> parameters1(0);9 ?9 h$ }( M. Z: H/ B
  81.     studioSplineBuilder1->SetParameters(parameters1);4 a/ n0 u4 n3 L) v: n. ]1 g0 T
  82.     Direction *nullDirection(NULL);% p2 y! D1 L+ R+ f4 |( ~
  83.     Scalar *nullScalar(NULL);% @* p5 V# s% V  ]; e3 n' X- f
  84.     Offset *nullOffset(NULL);& H* {0 \7 ~! {. W; H

  85. 4 |4 e! ~3 i; h6 O! X) _: W* M
  86.     std::vector<Features::GeometricConstraintData *>! D& `0 B% @: g# w
  87.         geometricConstraintData(thePoints.size());
    + T* V  C* Y: ]: y

  88. 3 ^) P3 F/ l  g: ^- y6 Z
  89.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)
    # D9 f  B+ {$ c3 [8 z
  90.     {' o# A( x7 n9 u5 V% E+ H6 g' g  A- i
  91.         geometricConstraintData[ii] = studioSplineBuilder1->7 t/ b; w: k. ~0 P; ~- p5 ?# h5 X
  92.             ConstraintManager()->CreateGeometricConstraintData();
    : u6 C8 ~5 k- a7 q9 O
  93.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);
    3 n4 I+ g# W5 v" o/ i0 _1 U+ ~
  94.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    * ~7 C6 o: d) S4 @' w
  95.             Features::GeometricConstraintData::ParameterDirectionIso);7 J% }- j+ g  j
  96.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    ) Z) I( k6 X1 ^5 s9 h9 y& h
  97.             Features::GeometricConstraintData::AutoConstraintTypeNone);
    # E5 _& J* h1 x- |* D
  98.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);8 }& U& e% ~6 o" R1 C; C
  99.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);$ L  x8 P* U- k7 c  g
  100.         geometricConstraintData[ii]->SetCurvature(nullOffset);
    . x8 w* c; [: x0 ?7 x5 S2 W
  101.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
    $ A; i" ~. {9 g% W! r& y8 K' u
  102.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
    7 B9 ^) F( a6 t  w
  103.     }
    - f; w, A' [2 P* }5 P: Q

  104. + q' W$ U. B7 V% N0 r  Z$ {
  105.     studioSplineBuilder1->ConstraintManager()->SetContents(2 Z( L( g/ n! ?1 e& s  v9 A# U
  106.         geometricConstraintData);% t, O0 Z( \/ h5 d  G+ h. E

  107. 5 j0 H2 D# a% m+ C/ o3 T% `# M
  108.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
    3 x  [4 j& U+ C% W0 q: o6 k1 H
  109.     Spline *theSpline = studioSplineBuilder1-><em>Curve</em>();
    6 {% f! S5 ?% @4 z3 S3 {! r

  110. # f# t7 E/ W0 q/ F6 s/ l
  111.     studioSplineBuilder1->Destroy();
    3 G3 R' P1 U- B

  112. 0 l5 Z; K. ~+ s
  113.     return theSpline;* y3 F# r" x& v$ ]# d9 u* s/ ^! S. h0 @
  114. }
    + _  D; g) H' O" c* l1 W. O

  115. # F0 D- o& j( M5 b6 [
  116. extern "<em>C</em>" DllExport void ufusr(char *param, int *retcod, int param_len)- h9 C) ^. Y: J4 G7 H
  117. {# h  e1 o1 r( W+ }) J
  118.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
    & a' t; ]6 Q# h( {$ m" I$ @" n
  119.     if (!thePoints.size()) return;
    " K4 w6 [: a) K- y; p' x
  120. 4 Q4 v6 c+ S6 |: \' {
  121.     Spline *theSpline = createStudioSplineThruPoints(thePoints);5 k% `3 l- a$ F$ d
  122. $ u: X! ?, p8 ?$ v
  123.     if (theSpline)  A) x1 H, h2 P8 t! {
  124.     {
    1 j3 l1 B$ _0 |$ I' b# w1 o
  125.         theSpline->Highlight();
    % c# n: _: F3 D0 m7 D
  126.         uc1601("Studio Spline Created Thru Points", TRUE);
    ! \7 {' @0 C1 e" w0 t8 p1 ~
  127.         theSpline->Unhighlight();
    5 a7 r/ d  Y, n/ t4 J& V0 E
  128.     }) b7 M: E: y* |" E3 l6 t
  129. }( j$ ]( Z- K4 x+ l2 T0 T. y
  130. <p> </p>
复制代码

1 K: w1 D: a4 S3 s/ [* o3 U- D
该会员没有填写今日想说内容.
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 注册

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

    本网站(plmhome.com)为PLM之家工业软件学习官网站

    展示的视频材料全部免费,需要高清和特殊技术支持请联系 QQ: 939801026

    PLM之家NX CAM二次开发专题模块培训报名开始啦

    我知道了