admin 发表于 2017-5-6 13:17:52

CATIA二次开发入门教程---15 通过点击屏幕创建点

CATIA二次开发入门教程---15 通过点击屏幕创建点
通过点击屏幕,自动创建点, 这里直接建立了一个简单的对话框,通过pushbutton来添加一个回掉函数,函数里面去执行创建点的类。


void DialogTestCmdDialog::OnPushButtonCreatePointPushBActivateNotification(CATCommand* cmd, CATNotification* evt, CATCommandClientData data)
{
// Add your code here
      CreatePointCmd *createPoint = new CreatePointCmd();
}

新建一个catia 的命令,名称为 CreatePointCmd ,接下来要做的就是在 action one 里面进行点的创建,代码如下:

CATBoolean CreatePointCmd::ActionOne( void *data )
{
// TODO: Define the action associated with the transition
// ------------------------------------------------------
CATMathPoint2D point2D =_Indication->GetValue();
CATMathPlane plane = _Indication->GetMathPlane();
CATMathPoint point3D;
plane.EvalPoint(point2D.GetX(),point2D.GetY(),point3D);

cout<<"Point coordinates:" << point3D.GetX() << "," << point3D.GetY() << "," << point3D.GetZ()<<endl;
   
//设置Container(非根节点)
//获得Editor
CATFrmEditor* pEditor = CATFrmEditor::GetCurrentEditor();
//得到当前对象的文档
CATDocument * pDocument = NULL ;
//取得当前活动对象
CATPathElement activePath = pEditor->GetUIActiveObject();
//取得当前活动的product
CATIProduct *pActiveProduct = (CATIProduct *)activePath.SearchObject(CATIProduct::ClassName());
//当前活动对象不存在
if (pActiveProduct == NULL)
{
    pDocument = pEditor->GetDocument();
}
else
{
    CATIProduct_var spRef = pActiveProduct->GetReferenceProduct();
    //当前对象的引用对象是否存在
    if ( NULL_var == spRef )
    {
      return FALSE;
    }
    //当前对象的链接对象
    CATILinkableObject * piLinkableObject = NULL;
    HRESULT rc = spRef->QueryInterface( IID_CATILinkableObject, (void**)& piLinkableObject );                           
    if ( FAILED(rc) )
    {
      piLinkableObject->Release();
      piLinkableObject = NULL ;
      return FALSE;
    }
    //得到当前对象的文档
    pDocument = piLinkableObject->GetDocument();
    piLinkableObject->Release();
    piLinkableObject = NULL ;
    if ( NULL == pDocument)
    {
      return FALSE;
    }
}
//得到文档容器集
CATIContainerOfDocument * pIContainerOfDocument = NULL;
HRESULT rc = pDocument->QueryInterface(IID_CATIContainerOfDocument, (void**)&pIContainerOfDocument);
if (FAILED(rc))
{
    //pIContainerOfDocument->Release();
    pIContainerOfDocument = NULL ;
    return FALSE;
}

//获得Document
CATIContainer* _pContainer = NULL;
//获得SpecContainer
HRESULT hr = pIContainerOfDocument->GetSpecContainer(_pContainer);

//GSM工厂
CATIGSMFactory_var spGSMFactory = NULL_var;
//设置工厂
spGSMFactory = _pContainer;         
CATIGSMPoint_var spPoint = spGSMFactory->CreatePoint(point3D);
CATISpecObject_var spSpecPoint= spPoint;   
CATIGSMProceduralView_var spSndPntObj = spSpecPoint;

//*将点显示在屏幕上
spSndPntObj->InsertInProceduralView();
//更新点对象
spSpecPoint->Update();

return TRUE;
}


效果如下:



onerice 发表于 2024-6-12 17:01:01

_Indication指的是什么呀
页: [1]
查看完整版本: CATIA二次开发入门教程---15 通过点击屏幕创建点