PLM之家精品课程培训

PLM之家精品课程培训

联系电话:18301858168   |   QQ咨询:939801026
NX二次开发培训

NX二次开发培训

UFUN/NXOpen C++和实战案例

适合初级入门或想深入了解二次开发的工程师,本培训结合ufun,NXOpen C++,大量的实例及官方内部的开发技术。
公众号二维码

关注公众号

点击扫描二维码免费在线高清教程

课程详情
Catia二次开发培训

Catia二次开发培训

市场需求大,掌握核心技术前景广阔

Catia二次开发的市场需求大,人才稀缺。掌握开发技能潜力巨大,随着经验积累将在汽车、航空等领域有所作为。
B站二维码

在线原创B站视频

点击关注工业软件传道士主页

课程详情
Teamcenter培训

Teamcenter培训

全方位培训,从基础应用到高级开发全覆盖

涵盖用户应用基础培训、管理员基础培训、管理员高级培训及二次开发培训等全方位内容,由多年经验讲师打造。
QQ群二维码

加入同行交流

点击扫描二维码加入QQ群

课程详情
×

PLM之家plmhome公众号

课程涵盖: PLM之家所有原创视频

×

关注B站视频

所有高清视频一览无余,全部在线播放学习

×

加入PLM之家QQ群

同行交流,疑问解答,更多互助

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

Catia二次开发源码分享:鼠标点击创建点

[复制链接]

2017-4-17 21:57:04 4726 0

admin 发表于 2017-4-17 21:57:04 |阅读模式

admin 楼主

2017-4-17 21:57:04

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

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

x

: C, I+ b! S' H3 w5 YCatia二次开发源码分享:鼠标点击创建点$ o. f  s3 L2 \0 m

1 K* _& y! a/ E) ]: k9 O
! i! a( g' _; f% S9 x; v#include "CAARCCreatePoint.h"
; w5 Z( \- `, l- k4 p7 U* V#include "CATIndicationAgent.h"
1 V$ E& ~( A  B. l2 d2 n#include "CATMathPlane.h"# p2 S! T' z" Y; _4 _
! m: }/ x- X, b2 g8 F2 I% y% @
#include "CATCreateExternalObject.h"
) q; h& K+ l* R6 R# |+ @0 m7 V+ s8 ]9 C
#include "CATMathPoint2D.h"
3 {4 j" @' J& [* `& O- t#include "CATMathPoint.h"8 C8 P) r: |2 U
#include "CATMathPlane.h"3 p4 t& J4 Q7 ]# L4 L2 A3 x. C$ ]4 ?1 f
( u0 U- |" f( l! i
#include "CATIGSMPoint.h"
. p8 h3 J& k4 t# Y7 g% c% U4 c8 }9 T
#include "CATFrmEditor.h"4 ?# n: x0 W7 ]1 a2 S
#include "CATPathElement.h"
1 K4 `/ g( s/ S. S( c/ M% i8 A  O- @  F, m8 v
#include "CATIProduct.h"2 `$ k0 g9 U$ S2 o8 [
#include "CATILinkableObject.h"" x' w+ n: L) r' p" i
#include "CATDocument.h"! ^% H6 b* X. |# {# r5 l
7 \8 h/ f! O2 n9 e, a3 p
#include "CATIContainerOfDocument.h"
. t2 E' y. \! n+ z
. G. C) m7 @0 K! {# a8 @) q9 c* s4 Z#include "CATIGSMProceduralView.h"
: v+ t  }+ ]/ o1 n$ u$ r
* }; f) X, S8 w6 w+ {/ e- F2 r#include "CATIContainer.h"
1 R; t2 e$ ?# A  Y& h#include "CATIGSMFactory.h"9 q; J/ Y6 ?$ v
  P9 ?+ T7 b# k5 K- K  n
#include "CATISpecObject.h"
/ d8 b/ f& E/ b: |# p#include "CATIGSMLinePtPt.h"
- v) o- H1 A! }3 f. _" l
+ \! v( ~) V: f, U- {#include "iostream.h"/ K5 B. g8 z9 t& O4 ?3 T; ]- b6 u6 ^
3 H4 B) C& Z# K2 R
CATCreateClass( CAARCCreatePoint);
; i2 h2 `1 K7 ?; u8 Y6 T# f) d% N0 G. d( |# Y( M, I' P# K

4 C; N5 h' {* g' V! a2 [0 S8 C& W//-------------------------------------------------------------------------. r8 g) h) m; f* b  Z/ f5 U; {
// Constructor
$ z( E0 j3 ^) @2 \  Y//-------------------------------------------------------------------------
. ~3 l+ S2 O6 J% K3 _& mCAARCCreatePoint::CAARCCreatePoint() :0 X. h; p- N9 s! P; y
  CATStateCommand ("CAARCCreatePoint", CATDlgEngOneShot, CATCommandModeExclusive) + v* l3 A) r8 s! D7 J2 `7 u1 k' X
//  Valid states are CATDlgEngOneShot and CATDlgEngRepeat
! ?) C/ l- N( L, p2 t' V! e& n  ,_Indication(NULL)
& v$ h- a, T# W3 j& b0 K{9 ?1 O/ T* X7 Q& d
}5 w1 ^1 ?! n% y
6 M* b$ b" `4 D
//-------------------------------------------------------------------------
. Y5 O- y; n' p6 @// Destructor
5 T5 F5 X& j9 F, w/ }) `0 q//-------------------------------------------------------------------------
, a0 I2 w8 b+ K8 hCAARCCreatePoint::~CAARCCreatePoint()9 E( t" Q$ R4 t5 w% W1 K
{
7 A- M" Y! m9 j   if (_Indication != NULL)
: y7 ]5 ~1 @$ N0 M  u: c      _Indication->RequestDelayedDestruction();) \' J' p6 e  b7 f$ {3 K; N* x
}4 R: q! @! B5 k3 L' c$ ^  D: F
/ Y, R$ M( I& X
" Q6 @. S; u4 X$ ~9 f6 c& E1 T
//-------------------------------------------------------------------------- p3 `9 f" _8 I' z! J7 f9 X# p
// BuildGraph()
' m# p% X$ {  b$ e2 i% z//-------------------------------------------------------------------------3 h$ o0 s  L; c5 b2 B) I
void CAARCCreatePoint::BuildGraph()5 d; e) U0 o# @; w4 q
{
3 a3 w  G/ Q1 ^) r+ e$ C# n2 \  // TODO: Define the StateChart 5 m% y) }2 d* D6 D
  // ---------------------------
& b$ x' M/ B" [4 g" K. [+ w( p: @  _Indication = new CATIndicationAgent ("Indication");
$ {) s7 V. E8 k. |8 q; e  _Indication->SetBehavior(CATDlgEngAcceptOnPrevaluate | CATDlgEngWithPrevaluation | CATDlgEngWithUndo );1 J5 f. S2 g% n' ?2 A* m* }/ O+ ~

, `1 v# L% {6 ]% Y, ]  AddCSOClient(_Indication);
( c& ~8 k/ x3 h7 S# x  //设置点所在的平面
" i4 D3 E, {5 b5 s' V  CATMathPlane PlaneXY;
' @6 i* q; F3 n! y  ~. _% E- T  _Indication -> SetMathPlane (PlaneXY);* k. y! j' k- W$ H* g' |$ v7 |" b

  c: l( s8 `7 D. i7 a/ O6 N. t  CATDialogState * initialState = GetInitialState("创建点");4 J& w: V/ D6 Q0 ?7 W, U
  initialState -> AddDialogAgent (_Indication);
! x4 C9 z; K+ P& F+ k' K$ \9 P1 P3 B- @
  AddTransition( initialState,
8 u$ G8 j( z  U; b) n5 Q6 [                 NULL,
: v4 P7 k) Q% ]% |                 IsOutputSetCondition (_Indication),4 F7 h% w$ @0 F, D- R
                 Action ((ActionMethod) &CAARCCreatePoint::ActionOne));/ G, o. j2 V% I& f. T; ~
}
; E* L  j# ~$ y, T; p" a, @0 ^: H" }$ d
3 ?; [% J( k6 G3 D
//-------------------------------------------------------------------------1 ^" o: b" t/ D7 H
// ActionOne ()
6 M* J0 D* n) U" f3 f3 d//-------------------------------------------------------------------------
& j- M" t5 {$ r6 c' _% bCATBoolean CAARCCreatePoint::ActionOne( void *data )
$ ]/ z+ N+ q$ x' l% e{7 ?# p: h  o, {& z8 w3 U3 ?
  // TODO: Define the action associated with the transition
! W7 c/ ^8 S8 C3 G  N2 U% X, W  // ------------------------------------------------------" H  p! _# y  H% ^- Q
  // 创建第一个点
" @  F% N* d7 ~$ Y  CATMathPoint2D point2D = _Indication->GetValue();//获得一个2D的点6 e6 {( u4 d* I, W* u
- v8 m0 \9 I/ u( d3 a
  CATMathPoint Point3D;
8 j; z" i. M) j7 S  CATMathPlane Plane = _Indication->GetMathPlane();
  W9 K4 c  m$ H: L$ _, E% g) r0 V. W' v
  Plane.EvalPoint(point2D.GetX(),point2D.GetY(),Point3D);                //将2D点转换为3D点/ h( S7 i* D& N( W' H7 t& q
. N* X$ x, w; I- y& s
  //设置Container(非根节点)  N/ T: y+ K) L9 x) {6 R
  //获得Editor
" |1 X3 u5 A% T  CATFrmEditor* pEditor = CATFrmEditor::GetCurrentEditor();( W) k; H6 x) A3 N* j4 X
; b/ X5 M# O+ t4 i# q
  //得到当前对象的文档
/ R$ Q4 E' ^2 q! m8 u  CATDocument * pDocument = NULL ;
( p! S( h% e* J
( ^$ P+ [9 B9 K; |  //取得当前活动对象  \8 E+ A# ~1 ]; C8 @" ?7 P
  CATPathElement activePath = pEditor->GetUIActiveObject();
4 q4 c3 M9 n/ l/ O/ @% S7 o1 ?, ^8 U$ ?  H- r
  //取得当前活动的product( J* s; @- v+ t+ K
  CATIProduct *pActiveProduct = (CATIProduct *)activePath.SearchObject(CATIProduct::ClassName());
7 {; i% g% v6 j3 t+ C- H. p2 i# B9 ?  v4 Q
  //当前活动对象不存在$ q# e5 d/ |: @
  if (pActiveProduct == NULL)5 k2 B: S, a* U* \/ J. y2 [
  {' f/ Y" @) M1 ~
    pDocument = pEditor->GetDocument();, h/ ?$ h9 i8 F2 O4 a: g
  }
/ S! R7 @& ~6 H' A, x( S) q) o  else$ D- [! e* v7 L' E3 ~: R$ M, t( |
  {
! e6 u! M- Y: ]7 g    CATIProduct_var spRef = pActiveProduct->GetReferenceProduct();
3 G, Z# f) G& g6 R9 u# c$ n" m; t    //当前对象的引用对象是否存在* @3 q; v- F0 e8 ~9 ?
    if ( NULL_var == spRef )
; w' Q9 u" W  I+ n, k    {
6 X0 ~  ?0 M' z4 B2 r      return FALSE;6 P9 p) V& k$ _% o6 Z3 G0 i
    }/ ~) y/ P- V' T3 e4 w2 M* B! u

4 Q5 {/ x3 g& J1 E0 X" h, n( X    //当前对象的链接对象7 l6 j# W$ d2 k8 r% f% R# u
    CATILinkableObject * piLinkableObject = NULL;
# h! L! j1 x( n, K    HRESULT rc = spRef->QueryInterface( IID_CATILinkableObject, (void**)& piLinkableObject );                           
" Y/ Z8 C% Y- q4 h% y    if ( FAILED(rc) )
7 f7 A' \3 B+ }0 f7 z    {: w4 A' m5 G" u+ Z$ @
      piLinkableObject->Release();
; X- l" q' z% p) X4 j1 f      piLinkableObject = NULL ;
4 ]+ H8 f0 _+ T0 K2 r/ L      return FALSE;# t/ a1 F+ }9 u+ k' }0 M
    }1 h: S0 I9 H2 d/ F  E7 n
" k% k4 X8 T: L3 k
    //得到当前对象的文档
# d! S4 k2 ]9 E/ M  F! [: g    pDocument = piLinkableObject->GetDocument();
% @# c; g$ o* F, s: L* |4 E    piLinkableObject->Release();( o3 s& x: L1 C7 ~2 K
    piLinkableObject = NULL ;" D  z2 _! C- G( `8 p; P( l" E0 y
0 t, i6 G6 U! N" b, N
    if ( NULL == pDocument)
2 {. _7 |- I# F9 l    {0 `8 r  C( K$ X. ^4 [8 h
      return FALSE;( L. A8 J8 ~8 U$ i
    }; y( a/ i8 g# g
  }
2 o& n. G: [/ _- g5 ~9 A1 V1 B2 S" P# b( K6 m4 l; C4 g
  //得到文档容器集" \4 ~* ^5 f! `' n
  CATIContainerOfDocument * pIContainerOfDocument = NULL;9 t0 \* R( h& f/ B8 Q
  HRESULT rc = pDocument->QueryInterface(IID_CATIContainerOfDocument, (void**)&pIContainerOfDocument);
5 M3 F: Z* j, J2 d  if (FAILED(rc))
1 `! m% x) w# q+ _; @  {
3 p" c4 y9 g% }3 h    //pIContainerOfDocument->Release();
% I. Z- b9 T/ k    pIContainerOfDocument = NULL ;. U0 m9 I0 o9 z  z# F
    return FALSE;+ Y6 a# v) z# \5 u; E& M
  }) _: N8 Q0 S! ~1 ]5 M0 G% I; j* Y( S
* F( ]  d- K! h1 Y' s5 e+ p7 j7 g
  //获得Document# `, u, Y# i% h) `9 h6 @# K  [
  CATIContainer* _pContainer = NULL;        % T, \5 G! n: \- I+ X
  //获得SpecContainer1 U( S" K7 _* w& q4 E* P2 x; i
  HRESULT hr = pIContainerOfDocument->GetSpecContainer(_pContainer);
) V/ S! b: {- X        . o( g; W! _9 ~; K1 S. {* z
  //GSM工厂
# w# n0 J- C7 f5 \! K. |6 i. ~. w0 m  CATIGSMFactory_var spGSMFactory = NULL_var;
. y9 K, _. x) c" C" p! ~/ o6 i  //设置工厂               
6 C! r% h2 G9 s+ A  spGSMFactory = _pContainer;                                                                        6 J/ V' N8 H! _# t

9 Z% D4 Y1 A) ~6 J7 Q, n% `  CATIGSMPoint_var spPoint = spGSMFactory->CreatePoint(Point3D);' d9 p1 N, b, I, M2 m
, [/ ?0 _5 ~' ]  t* H' w2 x
  CATISpecObject_var spSpecPoint= spPoint;                                        - v. R) x) `  J  J# W9 l

; ^$ K% V3 M3 w, n( X7 T; M  CATIGSMProceduralView_var spSndPntObj = spSpecPoint;
+ a& K& ]3 V2 c5 T$ k7 }3 i5 P
& c/ p, C# t( n9 o! q  //*将点显示在屏幕上
- ?9 P6 v" n. X  R: k0 b* b  spSndPntObj->InsertInProceduralView();! C: o" [, Y, a% P/ \9 p; Z

9 Q1 m& D: C  [# d  //更新点对象( ?8 N' M& q' |% E
  spSpecPoint->Update();, `$ c, a5 J; ~2 D
+ l" m+ F9 y- ~* O! N. Q+ E  O# ]
  return TRUE;
2 e8 |# i3 N' e, q. b% N. k}
; R' Q& E; u5 \% I6 j3 q' D  ^" o- L) v& Y7 ^( f, G8 N
5 q/ T; D, Y) y- }
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.diantuankj.com/ doTeam.tech
回复

使用道具 举报

发表回复

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

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

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

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

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

    我知道了