Mechanical Design |
Drafting |
Creating Annotations on View ComponentsHow to retrieve view components |
Use Case |
AbstractThis article discusses the CAADrwCoordinates use case. This use case explains how to retrieve the view components. |
This use case is intended to retrieve the view components. These components can be :
[Top]
CAADrwCoordinates is a use case of the CAADraftingInterfaces.edu framework that illustrates DraftingInterfaces framework capabilities.
[Top]
Fig. 1 represents a CATDrawing document containing 2D points.
Fig. 2 represents the previous CATDrawing after CAADrwCoordinates processing.
A text has been created near each point. This text is formatted like follows :
Point point index
X = the x point coordinate
Y = the y point coordinate
[Top]
To launch CAADrwCoordinates, you will need to set up the build time environment, then compile CAADrwCoordinates along with its prerequisites, set up the run time environment, and then execute the use case [1].
The CATDrawing document Fig. 1 is saved in the Framework CAADraftingInterfaces.edu/Cnext/Resources/graphic/CAADrwCoordinates.CATDrawing.
When you launch the use case, pass the full pathname of the file into which you you want to store the created document as argument: for example Result.CATDrawing.
e:> CAADrwCoordinates CAADrwCoordinates.CATDrawing Result.CATDrawing |
$ CAADrwCoordinates /u/users/CAADrwCoordinates.CATDrawing Result.CATDrawing |
[Top]
The CAADrwCoordinates use case is made of a single source file named CAADrwCoordinates.cpp located in the CAADrwCoordinates.m module of the CAADraftingInterfaces.edu framework:
Windows | InstallRootDirectory\CAADraftingInterfaces.edu\CAADrwCoordinates.m\ |
Unix | InstallRootDirectory/CAADraftingInterfaces.edu/CAADrwCoordinates.m/ |
where InstallRootDirectory
is the directory where the CAA CD-ROM
is installed.
[Top]
There are six steps in CAADRWCoordinates:
[Top]
int main(int iArgc, // Number of arguments (1) char** iArgv) // Path to the *.CATDrawing document { // Check arguments if(2 != iArgc) return 1; const char *fileName = iArgv[1]; // READ THE DRAWING DOCUMENT // ========================= // creates a session CATSession *pSampleSession = NULL; HRESULT hr = ::Create_Session("SampleSession",pSampleSession); if (FAILED(hr)) return 1; // read the document CATDocument* pDoc = NULL; if (!SUCCEEDED(CATDocumentServices::OpenDocument(fileName, pDoc))) { // Ends session ::Delete_Session("SampleSession"); return 2; } ... |
This section represents the usual sequence for reading a CATIA document [2].
[Top]
... // Gets the drawing feature using the CATIDftDocumentServices interface CATIDrawing *piDrawing = NULL; CATIDftDocumentServices *piDftDocServices = NULL; if (SUCCEEDED(pDoc->QueryInterface(IID_CATIDftDocumentServices, (void **)&piDftDocServices))) { piDftDocServices->GetDrawing(IID_CATIDrawing, (void **)&piDrawing); piDftDocServices->Release(); } if (NULL == piDrawing) return 3; ... |
The root feature of a drawing document is the Drawing, that is, the feature
that implements the CATIDrawing interface. We can get a pointer to CATIDrawing
using the CATIDftDocumentServices interface, which is implemented by the
document. The GetDrawing
method first argument is the CATIDrawing
interface IID.
[Top]
... // We can get the current sheet CATISheet_var spSheet = piDrawing->GetCurrentSheet(); // And the sheet current view CATIView_var spCurrentView = spSheet->GetCurrentView(); // Memory cleaning piDrawing->Release(); ... |
A drawing may contain several sheets, but only one is the current one. The current sheet is the sheet containing the active view, that is the view currently edited. The methods of the CATISheet and CATIView interfaces do return handlers, so we do not need to care about releasing them. The drawing variable is a pointer to CATIDrawing, so we have to release it when it is no longer used.
[Top]
... // Now we do seek all the points in the view CATIDescendants_var spDesc = spCurrentView; CATListValCATISpecObject_var pointList; spDesc->GetDirectChildren ("CATI2DPoint",pointList); ... |
The view geometry can be retrieved using the CATIDescendants interface. The first argument of the GetDirectChildren method is a scan filter. In this example, we only get points.
[Top]
... // loop on points for (int ii=1; ii<=pointList.Size(); ii++) { // Gets the coordinates CATI2DPoint_var spPoint = pointList[ii]; double coord[2]; spPoint->GetPointData(coord); // Compute the string CATUnicodeString textString("Point "); CATUnicodeString index; index.BuildFromNum(ii); textString += index; int titleLength = textString.GetLengthInChar(); textString.Append("\n"); textString.Append("X = "); CATUnicodeString coordText[2]; coordText[0].BuildFromNum(coord[0]); textString.Append(coordText[0]); textString.Append("\n"); textString.Append("Y = "); coordText[1].BuildFromNum(coord[1]); textString.Append(coordText[1]); // Creates the Text CATIDrwAnnotationFactory_var spAnnFactory = spCurrentView; CATIDftText *piDftText = NULL; const double txtpos[2] = {coord[0]+10.0,coord[1]+10.0}; if (SUCCEEDED(spAnnFactory->CreateDftText(txtpos, &piDftText))) { wchar_t *ptxtChar = new wchar_t[textString.GetLengthInChar()+1]; textString.ConvertToWChar(ptxtChar); piDftText->SetString(ptxtChar); delete [] ptxtChar; ptxtChar = NULL; CATIDrwSubString *piDrwSubString = NULL; if (SUCCEEDED(piDftText->QueryInterface(IID_CATIDrwSubString,(void **)&piDrwSubString))) { // Select the sub string to modifiable. piDrwSubString->SetSelection(1,8); // Modify the properties CATIDftTextProperties *piTextProp = NULL; if (SUCCEEDED(piDftText->GetTextProperties(&piTextProp))) { piTextProp->SetBold(TRUE); piTextProp->SetUnderline(TRUE); piTextProp->Release();piTextProp=NULL; } piDrwSubString->Release();piDrwSubString=NULL; } piDftText->Release();piDftText=NULL; } } ... |
We loop on the points and get the coordinates using CATI2DPoint::GetPointData.
The text string is computed using CATUnicodeString operators.
The CATIDrwAnnotationFactory annotation factory is implemented by the
view and so the coordinates passed in CreateDrwText
are view
coordinates. The CATIDrwTextProperties interface allows text property
modifications, such as setting the text with a bold typeface using the SetBold
method.
[Top]
... // Save the result hr = CATDocumentServices::SaveAs(*pDoc, (char *)fileNameOut); if (FAILED(hr)) return 4; // Ends session and drops document CATDocumentServices::Remove (*pDoc); ::Delete_Session("SampleSession"); return 0; } |
This section represents the usual sequence for saving a CATIA document [2].
[Top]
This use case shows how to get the view components. The view implements the CATIDescendants interface and the components can be retrieved by using the GetDirectChildren method.
This use case shows also how to open a CATDrawing document, get the root
feature which implements the CATIDrawing interface. A pointer to this
interface is the key to enter and navigate inside the drawing structure, and can
be retrieved using the GetDrawing
method of the CATIDftDocumentServices
interface implemented by the document. Retrieving the active view is performed
first by retrieving the current sheet thanks to the GetCurrentSheet
method of the CATIDrawing interface, and then asking the current sheet
for the current view using the GetCurrentView
of CATISheet.
This current view is scanned using the GetDirectChildren method of CATIDescendants.
The view also implements the CATIDrwAnnotationFactory interface and the
texts are created using its CreateDrwText
method, and set with a
bold typeface using the SetBold
method.
[Top]
[1] | Building and Lauching CAA V5 Samples |
[2] | Creating a New Document |
[Top] |
Version: 1 [Jan 2000] | Document created |
[Top] |
Copyright © 2000, Dassault Systèmes. All rights reserved.