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

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

[复制链接]

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

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

mildcat 楼主

2013-12-11 11:14:40

请使用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. 1 q# M  T# e4 S2 m8 ]8 P. M
  2. #include <uf_defs.h>
      G5 {, v( n3 [# p+ E
  3. #include <uf.h>
    % Q$ I5 Y" H6 j% F
  4. #include <uf_modl.h>' x! C; r, _% w5 c: E
  5. #include <uf_object_types.h>  p' k) T' _* g
  6. #include <uf_ui.h>
    4 ?7 y  B; o3 k7 p- s
  7. #include <uf_modl.h>
    $ i  E! a9 P8 f
  8. #include <<em>NXOpen</em>/NXException.hxx>
    4 I# D  \" ~* F6 J+ y; V
  9. #include <<em>NXOpen</em>/Session.hxx>
    0 i; s" L: Z1 }' S/ t0 w
  10. #include <<em>NXOpen</em>/Selection.hxx>* U, P5 A  {% p+ [; M# `) D
  11. #include <<em>NXOpen</em>/Builder.hxx>& _$ o2 B+ X) a0 `
  12. #include <<em>NXOpen</em>/Features_Feature.hxx>3 v. p1 i1 R/ t$ J9 a$ w
  13. #include <<em>NXOpen</em>/Features_FeatureBuilder.hxx>
    + J3 V  Z, w- ^: q& U3 |
  14. #include <<em>NXOpen</em>/Features_FeatureCollection.hxx>
    + E3 n2 M! C- J0 F3 D
  15. #include <<em>NXOpen</em>/Features_GeometricConstraintData.hxx>& x2 |, ]) v8 T  l, I8 A
  16. #include <<em>NXOpen</em>/Features_GeometricConstraintDataManager.hxx>
    ; S& {: m5 }! a
  17. #include <<em>NXOpen</em>/Features_StudioSplineBuilder.hxx>
    ) w7 r7 p( L8 A" ]7 R6 n& r0 l
  18. #include <<em>NXOpen</em>/Part.hxx>
    6 v8 \- H2 s8 h
  19. #include <<em>NXOpen</em>/ParTCollection.hxx>
    8 b. r+ u6 {% q' H; E
  20. #include <<em>NXOpen</em>/Point.hxx>: R( I% ?; K: v' w1 `- E) m
  21. #include <<em>NXOpen</em>/PointCollection.hxx>
    - u" T+ T) d* n/ P/ f/ ]
  22. #include <<em>NXOpen</em>/NXString.hxx>
    0 S" d( W6 w) J, W+ ?, k
  23. #include <<em>NXOpen</em>/UI.hxx>
    - I1 }" E) W: A8 Q% J9 l. f
  24. #include <<em>NXOpen</em>/Spline.hxx>
    7 n$ C# D7 {2 @/ |5 R
  25. #include <<em>NXOpen</em>/NXObjectManager.hxx>
    ' Z9 w+ f! q, M4 V& K5 F9 T8 f
  26. ; M  }8 J& i- j
  27. using namespace <em>NXOpen</em>;
    4 n0 G7 }9 O7 ]( n/ B
  28. using namespace std;8 }. n) H( Z' i% E
  29. ! z8 h; U+ ]2 L& N( Q; |
  30. extern "<em>C</em>" DllExport int ufusr_ask_unload()4 a" g" D& |/ t2 \% u
  31. {
    , Q6 F- V. r: n/ z, B6 S$ X2 J5 D
  32.     return (int)Session::LibraryUnloadOptionImmediately;* R  R. Y* O1 d0 s! \7 f
  33. }
    9 i/ ^( E8 R8 G0 `; C( \" M, S
  34. ) u' c  M5 f( U. V2 g+ u
  35. static vector<Point *> selectPoints(NXString prompt)( ~) B9 |9 i6 ^2 P) ~& F$ E
  36. {
    % G- R3 t7 O5 y0 n* _9 I2 f8 g
  37.     UI *ui = UI::GetUI();' E  C, H& r- @; J
  38.     Selection *sm = ui->SelectionManager();
    9 {5 P1 f- Y& {* l0 d
  39.     std::vector<Selection::MaskTriple> mask(1);! ?0 G8 L1 s- U5 [5 C$ x
  40.     mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);+ A3 U% m' s# F
  41.     std::vector<NXObject *> objects;; g# ]7 z0 ?6 Y6 j+ X6 s

  42.   X1 A* y' c# H4 V# X+ S+ ~' `- C
  43.     sm->SelectObjects("Select Points", prompt,
    - v/ H# @: F) f8 x* t
  44.         Selection::SelectionScopeAnyInAssembly,7 h, o; u! r: d9 b
  45.         Selection::SelectionActionClearAndEnableSpecific,$ ]- ]) W: |7 V8 l8 ^- f* D/ b. a
  46.         false, false, mask, objects);
    ; Q! h& ]9 O+ d6 {6 k

  47.   s; U$ @/ H. ~) ?, T. j
  48.     vector<Point *>selPoints(objects.size());
    - k; w+ a* m3 w) S5 W
  49.     for (unsigned int ii = 0; ii < objects.size(); ii++)1 V9 R6 w/ @2 w; _; K$ I- C# J  c+ Z
  50.         selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
    ! e1 o. e7 h* o2 y* E

  51. $ @: C3 X& U5 z% F, ^: N1 M/ T
  52.     return selPoints;0 `% R* W& K" z* Q$ `, D9 A- ]: k
  53. }! p6 b* @1 H( J- x+ {0 J; H. J: m

  54. ( b4 B: ^9 s/ T1 A, _: |" D
  55. static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
    2 w& \& i2 W/ H
  56. {
    8 J5 R% ?* \: m4 D3 X8 w
  57.     Session *theSession = Session::GetSession();
    & _* i2 p$ d, B6 e5 V
  58.     Part *workPart(theSession->Parts()->Work());
    & f" C  g! P/ R/ G! a1 m

  59. " Y/ q+ _( {3 M
  60.     Session::UndoMarkId markId1;, u$ g1 ^0 N& h" G' R! b; ?
  61.     markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
    ; X) _" u! W9 a% ~: T8 @+ K
  62.         "Studio Spline Thru Points");; b  y1 K- T  f5 C; D0 X
  63. ( T' [3 x, n3 L3 c
  64.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);8 g' v) t+ Z; m) o' W5 D& S
  65. " I7 Z8 O* Q" q( _# C% ^
  66.     Features::StudioSplineBuilder *studioSplineBuilder1;
      f/ l9 A1 Y3 f+ H! P
  67.     studioSplineBuilder1 = workPart->Features()->. _+ e1 \$ S3 p/ U- p, J7 |
  68.         CreateStudioSplineBuilder(nullFeatures_StudioSpline);0 f; P; @' I3 R: \( Y
  69.     studioSplineBuilder1->SetAssociative(true);4 G  U$ c/ |3 i! V: ?
  70.     studioSplineBuilder1->  Y) `- l* f* {
  71.         SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
    0 l* V2 S; N- e2 d: @
  72.     studioSplineBuilder1->
    - Q! }  ~/ a5 f
  73.         SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
    ! V. ~2 E7 Z1 P5 E/ M7 ?
  74.     studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);% H  b# ?% p# {6 q. g+ n
  75.     studioSplineBuilder1->SetPeriodic(false);2 \9 Y' N) [5 e2 K  Z0 U. _- [
  76.     studioSplineBuilder1->
    6 J; \3 s: }; b6 R
  77.         SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
    0 r. o4 O' K7 z  n& H
  78.     std::vector<double> knots1(0);8 J: A' g; P5 x+ Z
  79.     studioSplineBuilder1->SetKnots(knots1);
    & f7 f2 \3 R& l6 P3 U$ {. V
  80.     std::vector<double> parameters1(0);: V9 V$ P" _% j) t
  81.     studioSplineBuilder1->SetParameters(parameters1);: A! t* ^. k8 j# n
  82.     Direction *nullDirection(NULL);" E! E7 b4 ^' ]0 T! D) z
  83.     Scalar *nullScalar(NULL);7 n& Q/ D, p5 b( y- M$ F  |! {/ P& ?
  84.     Offset *nullOffset(NULL);4 W+ W5 d- D3 g$ l% P$ T6 u

  85. 7 Y0 Z) x% S5 X9 x; C
  86.     std::vector<Features::GeometricConstraintData *>' K* I  S% e3 B! Z4 m7 D
  87.         geometricConstraintData(thePoints.size());7 w* ^8 r+ F. Z! j, |) |
  88. ( ~7 c% j' E. F3 }! E; v/ j( S8 q$ {
  89.     for (unsigned int ii = 0; ii < thePoints.size(); ii++)8 z% {5 g4 T3 i9 I& Q$ [
  90.     {
    1 S  P& S3 ^7 V) e
  91.         geometricConstraintData[ii] = studioSplineBuilder1->) Y( ~& }1 `9 B
  92.             ConstraintManager()->CreateGeometricConstraintData();
    " K) X5 Q; l/ [
  93.         geometricConstraintData[ii]->SetPoint(thePoints[ii]);
    / T4 K' J8 s" A! b3 r9 B
  94.         geometricConstraintData[ii]->SetAutomaticConstraintDirection(
    6 u. J3 Y; v) r
  95.             Features::GeometricConstraintData::ParameterDirectionIso);
    / a2 G/ r" ^% r& S6 _
  96.         geometricConstraintData[ii]->SetAutomaticConstraintType(
    ( ~& ~0 H  y* c
  97.             Features::GeometricConstraintData::AutoConstraintTypeNone);3 [4 u3 ^& c4 D. ]6 `9 t- a
  98.         geometricConstraintData[ii]->SetTangentDirection(nullDirection);
    ' [$ q& z0 ~0 g* }* v. N  _% a) c
  99.         geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);! D3 ~5 u- k# P6 N
  100.         geometricConstraintData[ii]->SetCurvature(nullOffset);+ i& |7 W4 h6 \9 ~1 n* ?' \
  101.         geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
    / _7 |& N" a: m
  102.         geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
    . a2 v, |6 }) N4 K" V+ Y* f
  103.     }
    6 y; ~1 o7 A& p' [

  104. 0 O- V: N- d9 T6 s! [1 K6 H
  105.     studioSplineBuilder1->ConstraintManager()->SetContents(
    3 L/ h5 u/ Y, g" f  o/ ?! F
  106.         geometricConstraintData);0 y6 ^$ H3 n5 o) \1 }
  107. ) z8 S$ G2 c& r* b, g, f+ D
  108.     Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();0 z" g& S. Z. j: x  F/ |0 Z: Q
  109.     Spline *theSpline = studioSplineBuilder1-><em>Curve</em>();; |0 n2 ]* G7 f  h  x& d
  110. - V% @+ q9 C  I2 v) @
  111.     studioSplineBuilder1->Destroy();
    + p$ l: b( @1 g# s

  112. ! ~- J: |3 t% e8 u! y0 _! I  _
  113.     return theSpline;6 s' {2 v0 U9 X% L" N7 B% u* a
  114. }1 ]7 C3 K5 E  O5 N# A. l
  115. % D% }6 d- N" K5 \& ^4 g& n, N. D
  116. extern "<em>C</em>" DllExport void ufusr(char *param, int *retcod, int param_len)* Y; P% j( q+ K. u3 ?- y
  117. {
    * f0 B; [% Q# K% ]+ z$ Z% A
  118.     std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");$ E3 k6 _2 O, J& J# _
  119.     if (!thePoints.size()) return;8 D8 ~# q7 G  _- A! ]# S7 e% ^/ E" s

  120. 4 z/ k8 x+ O! r, I# J& l: N
  121.     Spline *theSpline = createStudioSplineThruPoints(thePoints);
    % d) @* W3 w! y6 o& U) d) a
  122. ) f+ |; v6 `( r. }) d2 W
  123.     if (theSpline)
    $ m% e7 l8 v& q" k7 ^1 s
  124.     {( ^9 V# u5 \7 N& m& ~, n. b
  125.         theSpline->Highlight();
    ) b4 A- l' a! X7 `
  126.         uc1601("Studio Spline Created Thru Points", TRUE);& u1 w2 c( i; m1 H) S
  127.         theSpline->Unhighlight();
    , r, N* M' P& ^% v- R5 D
  128.     }9 \, @' [: n7 h1 k5 c
  129. }
    7 E' f9 y& X! H
  130. <p> </p>
复制代码

. ?! F. T, u4 S6 s3 A. p2 S+ v2 }
该会员没有填写今日想说内容.
回复

使用道具 举报

发表回复

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

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

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

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

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

    我知道了