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 4713 0

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

admin 楼主

2017-4-17 21:57:04

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

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

x
& n2 o1 F7 {% x
Catia二次开发源码分享:鼠标点击创建点
  _6 X0 M, S% X  K% k8 D; L
% ?) M! ~; \; w. u$ R( J
# K5 u" q  k9 x& T! D#include "CAARCCreatePoint.h"5 B- Z1 O9 P8 ~9 M8 z- k. |
#include "CATIndicationAgent.h") h  S1 g* U5 p- u- X: Z+ A
#include "CATMathPlane.h"
$ b, u# W) F# ?; l$ e0 P( z( ~; \. u, D4 s& X4 T
#include "CATCreateExternalObject.h"
% H7 ^) J8 w: @6 m& W& _
+ p8 C6 U0 W. ~' }$ @) m. ^3 j#include "CATMathPoint2D.h"* m) w( f* e' _/ J  M* Z
#include "CATMathPoint.h", V% ~2 ?( a5 K. c
#include "CATMathPlane.h"
' B2 c' D# L1 \. T
' b) U/ M; E& g! \- J#include "CATIGSMPoint.h"+ H, S8 P) X% H* V. l
1 c* G, R+ g- I: x
#include "CATFrmEditor.h"1 V( [0 u' H2 g. J& l
#include "CATPathElement.h"* l# L+ V8 {: |0 p
: M$ I' n; i  f& o
#include "CATIProduct.h"0 }& n! c: K  \( u
#include "CATILinkableObject.h"
5 f1 z+ S: [) V5 c# l0 ^#include "CATDocument.h"
/ E1 O. Y2 r) I) }# q9 _5 k% w3 E( P; j6 K4 i. s
#include "CATIContainerOfDocument.h"4 P1 z2 E- l9 }& m! G" J1 L6 S
2 b. y3 \( F7 C9 C
#include "CATIGSMProceduralView.h"# K" f( w- v+ W6 ^( Z2 R
) E3 Z; O3 J4 d1 q) m% ~# _. h% y$ Q
#include "CATIContainer.h"
, a3 ^+ `6 \6 u  i" u#include "CATIGSMFactory.h"
, z: R$ b# t. H7 E4 G$ {/ J, K: ]  V6 h! U2 p# R- j) q2 [
#include "CATISpecObject.h"
5 G3 E! j! E. f, |#include "CATIGSMLinePtPt.h"
1 |% t; t7 h9 d
/ p4 ^5 b% N( L. `5 I% a3 N#include "iostream.h". o" B+ b$ S& K+ v) B* ]! c
& ]- q( p  Q( q! {8 B9 a
CATCreateClass( CAARCCreatePoint);
, F- l3 N$ x  l: m- b( I+ r$ F+ t: ~2 z# x. b8 B1 ~
2 e$ |9 T+ K6 L- e) g0 G
//-------------------------------------------------------------------------
, w; V  A2 ?( Q. }. K) `+ o// Constructor
8 U" M7 T! v1 B. ~6 S5 ^, h) B//-------------------------------------------------------------------------
3 z2 @1 P& H% a/ B6 y+ I3 N$ I' SCAARCCreatePoint::CAARCCreatePoint() :8 U, f  p' s9 h4 _! M9 }, E
  CATStateCommand ("CAARCCreatePoint", CATDlgEngOneShot, CATCommandModeExclusive) ' y4 C7 @+ h: r; S" _
//  Valid states are CATDlgEngOneShot and CATDlgEngRepeat
, a9 M/ v" f3 w$ z/ N  ,_Indication(NULL)
$ a) ^1 U; Z! H+ P0 _{
) m7 H7 e; J2 N% J" o4 T( D}' F9 i$ D/ O0 V
9 e/ ~* \7 h, C6 S& I- j  n
//-------------------------------------------------------------------------
, v( O' O, H  s/ [  J// Destructor
; N- H9 R, O" B0 \& o" {, u//-------------------------------------------------------------------------+ X  W" E& t. l1 ^$ N6 z
CAARCCreatePoint::~CAARCCreatePoint()
4 k$ m  o1 Q1 c{
& i( {( h. s& l7 H2 H   if (_Indication != NULL)
& F0 }" W7 w8 I6 ^* ^1 `      _Indication->RequestDelayedDestruction();. [( j6 [! C8 W# I. @' F
}# k+ `' O$ c! S3 i2 P/ p

" o' c1 ~0 q7 V
* R- S0 O! `: G# k% `; \//-------------------------------------------------------------------------# f# t$ K4 q! a9 Z0 i) }7 _
// BuildGraph()
, z5 o( p- R/ |( |//-------------------------------------------------------------------------9 Z( K3 \% s$ u( S7 w/ j5 G
void CAARCCreatePoint::BuildGraph()' p2 f7 e4 B4 ]9 D5 v$ d% N
{
9 C& h# E# O6 r+ D+ d( T  // TODO: Define the StateChart 9 {9 s4 D: [) v
  // ---------------------------
' q6 h1 Y. s1 A, z4 D7 r9 u  _Indication = new CATIndicationAgent ("Indication");, I( L( q: d2 F- Q8 N9 c+ F$ y
  _Indication->SetBehavior(CATDlgEngAcceptOnPrevaluate | CATDlgEngWithPrevaluation | CATDlgEngWithUndo );
3 ?9 P4 s- g* P  T3 u+ M/ l* {4 N4 ~& q3 M" y1 w
  AddCSOClient(_Indication);
$ g/ f; m' l: W- P  //设置点所在的平面. j+ }: X+ Z, i& M4 j6 z
  CATMathPlane PlaneXY;
! f0 E. J4 G6 N. \  _Indication -> SetMathPlane (PlaneXY);
( ?$ L% A+ z+ ?# }/ {
6 q& n& x9 M- e5 Z0 F  @- S  CATDialogState * initialState = GetInitialState("创建点");
& e3 ~' c4 d' A! N5 v  initialState -> AddDialogAgent (_Indication);% w% g6 @: o9 i3 `2 G/ x8 C* n
" P1 X3 {9 |& y# j( F3 y; h1 x6 b2 p
  AddTransition( initialState, ( R$ F( r6 D9 v% b
                 NULL,
# H  }+ A+ `/ |+ q! o                 IsOutputSetCondition (_Indication),  X9 Z! p: Y  G3 N
                 Action ((ActionMethod) &CAARCCreatePoint::ActionOne));# _0 o& v5 K1 d  P: I, _
}2 _3 z7 D, b0 m, ]% y* c3 g

' }* ~& Y4 ]' w* _
3 X0 d4 N5 `  l! H" P: D- D2 o//-------------------------------------------------------------------------" E$ i8 |* R) I0 ]6 h" {" E6 D- r: u
// ActionOne ()6 R+ x3 O& _6 H: F
//-------------------------------------------------------------------------
" [$ O, ]. V+ A- m8 D$ nCATBoolean CAARCCreatePoint::ActionOne( void *data )
5 j6 Z' L8 t" Y9 i: y7 D{+ x# s5 r  H* Y9 ~3 v4 q
  // TODO: Define the action associated with the transition
. E+ z4 a  G* D  // ------------------------------------------------------
8 l8 _) R+ D6 H  // 创建第一个点3 v! h/ t8 P3 e. I9 P$ A
  CATMathPoint2D point2D = _Indication->GetValue();//获得一个2D的点
; U  y4 E3 L" ^* g- m! `; @7 p. [+ p6 l" C+ L/ y
  CATMathPoint Point3D;
' {+ e; A% R" D" u+ E  CATMathPlane Plane = _Indication->GetMathPlane();
3 S1 K5 V) f  ~) h  ?3 T
9 h$ X$ l3 [8 o. I  Plane.EvalPoint(point2D.GetX(),point2D.GetY(),Point3D);                //将2D点转换为3D点
5 s8 v% Q% c8 e0 s7 V( v& X' s3 j+ b
/ c" d$ x# f1 [6 S. D$ z$ b) r  //设置Container(非根节点)
$ {# Y8 f9 v5 D3 ?" V/ ^  //获得Editor2 T3 \! ^; ~$ z9 v( R6 a) x
  CATFrmEditor* pEditor = CATFrmEditor::GetCurrentEditor();
; T+ V; Z' h* q6 x$ z9 Z
2 J% D1 v6 |: w+ O  K5 R+ i  u  //得到当前对象的文档
8 t- t7 m& \% N& x5 Q. r  CATDocument * pDocument = NULL ;2 @: F& g3 H( U4 b) H
. s  Y+ Z" c/ K2 e! B( f
  //取得当前活动对象
" {& q- B% t' x% C, `  CATPathElement activePath = pEditor->GetUIActiveObject();
; t7 ^% G7 G1 U
3 T% ?! g8 I2 y. W3 w: I  //取得当前活动的product: e! |8 r9 S% q2 Q" f
  CATIProduct *pActiveProduct = (CATIProduct *)activePath.SearchObject(CATIProduct::ClassName());
0 t( {  s; e; M) ^
3 \5 a5 m- z$ y$ g" k  //当前活动对象不存在
( i/ o% k9 R! `0 X  if (pActiveProduct == NULL)
9 G- y6 }* x1 G) U  {0 q1 W6 _! [; K: }7 B$ o- V
    pDocument = pEditor->GetDocument();4 |( p# ^2 q; z
  }. U1 w9 T. S1 P6 ]/ @+ O0 N5 _' e7 Z+ L
  else
" M! p, a* y1 {% O2 I  I& H  {
( Q6 y7 T5 ?% r; W, X: `    CATIProduct_var spRef = pActiveProduct->GetReferenceProduct();1 w0 E( N& C5 S+ p5 N- v! ]- k
    //当前对象的引用对象是否存在
0 s, A8 r. W! E! S4 w: k  m* F    if ( NULL_var == spRef )
. u  E2 V  _8 f9 {    {
" @! c9 \$ K6 c- @0 u  C6 o- G( ?3 }4 L      return FALSE;. E: x, G/ Z+ A/ ]9 f1 |
    }
( s, [" r6 C! a3 ]; O9 X4 d9 O' F+ ~& q
    //当前对象的链接对象
5 a" _! W) w0 a( W4 J" i- h    CATILinkableObject * piLinkableObject = NULL;5 U/ N( I) S( L; Q# z3 J# x$ Y7 u  y0 \
    HRESULT rc = spRef->QueryInterface( IID_CATILinkableObject, (void**)& piLinkableObject );                            ' _, R, }; |& n5 o3 }6 e* p- v
    if ( FAILED(rc) )  q: J6 `% ^. E1 {
    {- [7 e* b! G  I# q- m
      piLinkableObject->Release();
# z6 q! s" l: D+ g      piLinkableObject = NULL ;
; t' R' U: J' G4 {, A1 ~8 m      return FALSE;
. w* {8 F( @1 V0 X' X    }- x; V. u+ n$ n" X2 U; h: k; J

/ N" H/ H  K! x0 t/ {9 f    //得到当前对象的文档9 E5 j9 x: f8 ~# o
    pDocument = piLinkableObject->GetDocument();
. i9 p/ T9 W1 l. ^: s    piLinkableObject->Release();. v6 w6 g, q* i' W+ R( C
    piLinkableObject = NULL ;, z& d* v2 `' Y8 g+ q2 b

: F- _' W! u/ k0 B9 D' _/ W' t    if ( NULL == pDocument)
7 }0 k4 I1 p6 E( J% ?* c; j    {2 W' `. e/ b* S; z6 D3 l% a) H
      return FALSE;: \4 K1 v, x' w7 c
    }
1 g9 \# |: a1 M8 b4 R& h4 B- u' h  }: I/ Z/ F. d* u: h
( e5 j% t: V+ A. |- c
  //得到文档容器集+ Q' `; ^9 d+ ~1 j6 h; s
  CATIContainerOfDocument * pIContainerOfDocument = NULL;
6 d" t, i! G7 j3 i* `  HRESULT rc = pDocument->QueryInterface(IID_CATIContainerOfDocument, (void**)&pIContainerOfDocument);7 L" V* v. Y' `9 B2 I+ e6 W7 q& x3 H
  if (FAILED(rc)), f- z! S! V5 @/ h# L
  {; B1 |: C9 L5 Q5 [9 d
    //pIContainerOfDocument->Release();3 m0 @: P: |, Z6 ~
    pIContainerOfDocument = NULL ;
: b5 m0 P6 T- v8 Y, I0 W9 N    return FALSE;& k% F/ ?( p! L4 d' F: D8 n
  }
* G6 ]/ b% W; W
/ M  o, |7 O: l3 p9 B! b  //获得Document
5 E: h0 B4 M# t  e  CATIContainer* _pContainer = NULL;        , _% v9 A3 X  d/ U' f
  //获得SpecContainer
6 X' X1 U' I- {! ?/ z1 \  HRESULT hr = pIContainerOfDocument->GetSpecContainer(_pContainer);
4 O  R7 J' r' r" @* O. c' P       
" [6 r# ?8 e$ n2 B( t/ [* r  //GSM工厂9 G% Q, X: U% Y) p2 ?( D% M
  CATIGSMFactory_var spGSMFactory = NULL_var;
7 l* x" N& j4 O  //设置工厂                , }' M. w% {  c% G, Q1 j" Y. Z6 I
  spGSMFactory = _pContainer;                                                                        / Y, r1 U* Y- j, K& W
5 N  T6 g7 m- T; ~+ E" n' p5 H
  CATIGSMPoint_var spPoint = spGSMFactory->CreatePoint(Point3D);
  R' l- _# K! z3 Q$ g) J* u" x. I2 H
* y+ |2 _' `: S  CATISpecObject_var spSpecPoint= spPoint;                                       
, Z' X" z$ Z+ W6 i1 O- L% N" I; w0 G0 j  \
  CATIGSMProceduralView_var spSndPntObj = spSpecPoint;. ^+ r" J/ W* j) G+ ^% r

5 W! f; S5 d5 I' Z5 n3 d8 S  //*将点显示在屏幕上7 r8 I- E' H& A4 C  v, v9 k
  spSndPntObj->InsertInProceduralView();- m, [  w8 z' c# Y# |
' a& u" h" E4 J; z7 z) l( @
  //更新点对象
$ _8 a4 Z  a+ x, _7 l  spSpecPoint->Update();8 p; \" _6 P: |4 B7 r

" V4 ?( r9 b( H# }1 E$ ^: a  return TRUE;& O! {. A$ |5 f9 y' M
}; ~# T3 t8 Q% T' V7 S' r
3 g; [( B2 `/ a" T* j

$ |0 o) Y3 D) V+ ~) @
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了