Mechanical Design |
Drafting |
Creating a Multi Sheet Interactive CommandHow to create an interactive command working on several sheets |
Use Case |
AbstractThis article discusses the CAADrwMultiSheetCmd use case. This use case explains how to create a command working on several sheets. |
In this use case you will learn how to create an interactive command working on several sheets.
[Top]
CAADrwMultiSheetCmd is a use case of the CAADraftingInterfaces.edu framework that illustrates DraftingInterfaces framework capabilities.
[Top]
This use case shows a command working on several sheets. The use case interactive command has two steps:
[Top]
To launch CAADrwMultiSheetCmd, you will need to set up the build time environment, then compile CAADrwMultiSheetCmd and CAADrwAddin along with its prerequisites, set up the run time environment, and then include the command in a workbench [1].
[Top]
The CAADrwMultiSheetCmd use case is made of two source files named CAADrwMultiSheetCmd.h and CAADrwMultiSheetCmd.cpp located in the CAADrwMultiSheetCmd.m module of the CAADraftingInterfaces.edu framework:
Windows | InstallRootDirectory\CAADraftingInterfaces.edu\CAADrwMultiSheetCmd.m\ |
Unix | InstallRootDirectory/CAADraftingInterfaces.edu/CAADrwMultiSheetCmd.m/ |
where InstallRootDirectory
is the directory where the CAA CD-ROM
is installed.
[Top]
There are seven steps in CAADrwMultiSheetCmd:
[Top]
// ---------------------------------------------------------------------------- CAADrwMultiSheetCmd::CAADrwMultiSheetCmd() :CATStateCommand(CATString("AlignText")), _pObjectAgent(NULL) { // Get the current drawing from the frame __piSheetsOnDrawing = NULL; CATApplicationFrame *appFrame = CATApplicationFrame::GetFrame(); CATIAApplication *ptApp = NULL; if (SUCCEEDED(appFrame->QueryInterface(IID_CATIAApplication, (void**) &ptApp))) { CATIADocument *ptDoc = NULL; if (SUCCEEDED(ptApp->get_ActiveDocument(ptDoc))) { CATIADrawingDocument *piDrawing = NULL; if (SUCCEEDED(ptDoc->QueryInterface(IID_CATIADrawingDocument, (void**) &piDrawing))) { piDrawing->get_Sheets(__piSheetsOnDrawing); piDrawing->Release(); } ptDoc->Release(); } ptApp->Release(); } // Save Multi sheet mode to restitute it at the end of the command GetMultiSheetMode(_PreviousMode); // Activate Multi sheet mode if (!_PreviousMode) SetMultiSheetMode(TRUE); _Xposition =0.0; _Yposition =0.0; } |
[Top]
// ---------------------------------------------------------------------------- // Save Multi sheet mode to restore it at the end of the command GetMultiSheetMode(_PreviousMode); // ... // This internal method is used to manage CATIDftMultiSheetCmd Interfaces. void CAADrwMultiSheetCmd::GetMultiSheetMode(boolean &oMode) { oMode = FALSE; if (!!__piSheetsOnDrawing) { CATIDftMultiSheetMode *multiSheetManager=NULL; if (SUCCEEDED(__piSheetsOnDrawing->QueryInterface(IID_CATIDftMultiSheetMode, (void **) &multiSheetManager))) { multiSheetManager->GetMultiSheetMode(&oMode); multiSheetManager->Release(); } } } |
[Top]
// Active Multi sheet mode if (!_PreviousMode) SetMultiSheetMode(TRUE); ... //This internal method is used to manage CATIDftMultiSheetCmd Interfaces. void CAADrwMultiSheetCmd::SetMultiSheetMode(boolean iMode) { if (!!__piSheetsOnDrawing) { CATIDftMultiSheetMode *multiSheetManager=NULL; if (SUCCEEDED(__piSheetsOnDrawing->QueryInterface(IID_CATIDftMultiSheetMode, (void **) &multiSheetManager))) { multiSheetManager->SetMultiSheetMode(iMode); multiSheetManager->Release(); } } } |
[Top]
// ---------------------------------------------------------------------------- void CAADrwMultiSheetCmd::BuildGraph() { // Creation of the acquisition agent _pObjectAgent = new CATPathElementAgent("pObjectAgent"); _pObjectAgent ->SetBehavior( CATDlgEngWithPrevaluation | CATDlgEngMultiAcquisition | CATDlgEngWithCSO); // We want to select text _pObjectAgent ->SetElementType("CATIDrwText"); AddCSOClient(_pObjectAgent); // States definition CATDialogState* state1 = GetInitialState("Sel reference text"); CATDialogState* state2 = AddDialogState("Sel text to align"); state1->AddDialogAgent(_pObjectAgent); state2->AddDialogAgent(_pObjectAgent); // Transition definition AddTransition(state1, state2, IsOutputSetCondition(_pObjectAgent), Action((ActionMethod)&CAADrwMultiSheetCmd::CheckText, NULL, NULL)); // Transition definition AddTransition(state2, NULL, IsOutputSetCondition(_pObjectAgent), Action((ActionMethod)&CAADrwMultiSheetCmd::MoveText, NULL, NULL)); } |
In this section we create a CATPathElementAgent and set the corresponding element type to CATIDrwText. So only Complex Texts could be selected.
[Top]
// ---------------------------------------------------------------------------- boolean CAADrwMultiSheetCmd::CheckText(void *) { // We get the Selected set of objects CATSO* pObjSO = _pObjectAgent->GetListOfValues(); CATPathElement *pElemPath = NULL; if (NULL != pObjSO) { // There is a selection, we will scan it from the beginning pObjSO->InitElementList(); while (NULL != (pElemPath = (CATPathElement*)pObjSO->NextElement())) { // Make sure the element is a text CATIDrwText *piText = (CATIDrwText *)pElemPath->FindElement(IID_CATIDrwText); if (NULL != piText) { piText->GetPosition(_Xposition,_Yposition); piText->Release(); } } _pObjectAgent -> InitializeAcquisition(); return TRUE; } return FALSE; } ... |
The acquisition agent did put the selected text into the CSO. So we get the set of object and loop on it.
[Top]
// ---------------------------------------------------------------------------- boolean CAADrwMultiSheetCmd::MoveText(void *) { // We get the Selected set of objects CATSO* pObjSO = _pObjectAgent->GetListOfValues(); CATPathElement *pElemPath = NULL; if (NULL != pObjSO) { // There is a selection, we will scan it from the beginning pObjSO->InitElementList(); while (NULL != (pElemPath = (CATPathElement*)pObjSO->NextElement())) { // Make sure the element is a text CATIDrwText *piText = (CATIDrwText *)pElemPath->FindElement(IID_CATIDrwText); if (NULL != piText) { piText->SetPosition(_Xposition,_Yposition); CATIModelEvents_var event(piText); if (event !=NULL_var) { CATModify info((CATBaseUnknown *)piText); event->Dispatch(info); } piText->Release(); } } _pObjectAgent -> InitializeAcquisition(); return TRUE; } ... |
Note: When a text is modified and needs to regenerate its graphical representations, it just has to send CATModify event to warn all its.
[Top]
... // Restore Active Multi sheet mode SetMultiSheetMode(_PreviousMode); return FALSE; } |
Note: The Multi Sheet Mode Value has to be restore in the destructor.
[Top]
This use case shows how to create a command working on several sheets: Retrieve current drawing, manage the multi sheet Mode and move a text.
[Top]
[1] | Building and Lauching CAA V5 Samples |
[2] | Implementing the Statechart Diagram |
[Top] |
Version: 1 [Aug 2000] | Document created |
[Top] |
Copyright © 2000, Dassault Systèmes. All rights reserved.