前言
跨文档选择数据最常见的例子是原生功能中在工程图选择需要投影的视图平面及方向等,具体例子参考投影视图的创建
核心接口
需要使用的两个接口 CATMultiDocumentCommand与 CATOtherDocumentAgent
官方说明
具体流程
实现CATMultiDocumentCommand子类
SelectProductCmd.h头文件
// COPYRIGHT Dassault Systemes 2012
//===================================================================
//
// SelectProductCmd.h
// The state chart based command: SelectProductCmd
//
//===================================================================
//
// Usage notes:
//
//===================================================================
//CAA2 Wizard Generation Report
// STATECOMMAND
//End CAA2 Wizard Generation Report
//
// Dec 2012 Creation: Code generated by the CAA wizard Administrator
//===================================================================
#ifndef SelectProductCmd_H
#define SelectProductCmd_H
#include "CATMultiDocumentCommand.h"
#include "CATBoolean.h"
#include "CATPathElementAgent.h"
class CATPathElementAgent;
//----------------------------------------------------------------------
/**
* Describe your command here.
* <p>
* Using this prefered syntax will enable mkdoc to document your class.
* <p>
* refer to programming resources of Dialog engine framework.
* (consult base class description).
*/
class SelectProductCmd: public CATMultiDocumentCommand
{
// Allows customization/internationalization of command's messages
// ---------------------------------------------------------------
CmdDeclareResource( SelectProductCmd, CATMultiDocumentCommand )
public:
SelectProductCmd();
virtual ~SelectProductCmd();
/**
* Defines the command automata.
* <br>
* <i>(states, transitions and agents)</i>
*/
virtual void BuildGraph();
private:
// Copy constructor, not implemented
// Set as private to prevent from compiler automatic creation as public.
SelectProductCmd(const SelectProductCmd &iObjectToCopy);
// Assignment operator, not implemented
// Set as private to prevent from compiler automatic creation as public.
SelectProductCmd & operator = (const SelectProductCmd &iObjectToCopy);
/**
* Action associated to state transitions.
*/
virtual CATBoolean ActionOne(void * data);
private:
CATPathElementAgent m_SelectAgent;
};
//----------------------------------------------------------------------
#endif
cpp
// COPYRIGHT Dassault Systemes 2012
//===================================================================
//
// SelectProductCmd.cpp
// The state chart based command: SelectProductCmd
//
//===================================================================
//
// Usage notes:
//
//===================================================================
//
// Dec 2012 Creation: Code generated by the CAA wizard Administrator
//===================================================================
#include "SelectProductCmd.h"
#include "CATIndicationAgent.h"
#include "CATMathPlane.h"
#include "CATOtherDocumentAgent.h"
#include "CATCreateExternalObject.h"
CATCreateClass( SelectProductCmd);
//-------------------------------------------------------------------------
// Constructor
//-------------------------------------------------------------------------
SelectProductCmd::SelectProductCmd() :
//CATStateCommand ("SelectProductCmd", CATDlgEngOneShot, CATCommandModeExclusive)
// Valid states are CATDlgEngOneShot and CATDlgEngRepeat
m_SelectAgent("SelectProductCmdId")
{
}
//-------------------------------------------------------------------------
// Destructor
//-------------------------------------------------------------------------
SelectProductCmd::~SelectProductCmd()
{
}
//-------------------------------------------------------------------------
// BuildGraph()
//-------------------------------------------------------------------------
void SelectProductCmd::BuildGraph()
{
// TODO: Define the StateChart
// ---------------------------
if( NULL != _fromCommand )
{
m_SelectAgent.SetBehavior(_fromCommand->GetBehavior());
}
else
{
m_SelectAgent.SetBehavior(CATDlgEngWithPSOHSO);
}
m_SelectAgent.SetElementType("CATIProduct");
//m_SelectAgent.SetElementType("CATIPrtPart");
CATDialogState * gsmState = GetInitialState("请选择零部件");
gsmState->AddDialogAgent(&m_SelectAgent);
AddTransition( gsmState, NULL, NULL,
Action ((ActionMethod) &SelectProductCmd::ActionOne));
}
//-------------------------------------------------------------------------
// ActionOne ()
//-------------------------------------------------------------------------
CATBoolean SelectProductCmd::ActionOne( void *data )
{
// TODO: Define the action associated with the transition
// ------------------------------------------------------
if (m_SelectAgent.GetBehavior() & CATDlgEngMultiAcquisition)
{
ReturnListOfValues(m_SelectAgent.GetListOfValues());
}
else
{
ReturnValue(m_SelectAgent.GetValue());
}
return TRUE;
}
在需要使用CATOtherDocumentAgent
m_SelectOtherDocAgent = new CATOtherDocumentAgent("FeatureSelectAgent", "SelectProductCmd", "CATPathElementAgent");
m_SelectOtherDocAgent -> SetBehavior( CATDlgEngWithPSOHSO | CATDlgEngWithPrevaluation | CATDlgEngRepeat | CATDlgEngNewHSOManager );
m_SelectOtherDocAgent -> AddElementType("CATIProduct");
//获取选择的数据
//CATPathElement *pEle = m_SelectOtherDocAgent -> GetValue();
//m_SelectOtherDocAgent -> InitializeAcquisition();
注意构造CATOtherDocumentAgent中第二个参数 "SelectProductCmd"为上一步构造出的cmd名称
选择类型Addtype需要对上