Mechanical Design |
Drafting |
Editing Generated Geometry in a Generative ViewHow to access generated geometry |
Use Case |
AbstractThis article discusses the CAADrwGeomAccess use case. This use case explains how to a geometrical elements generated from 3D elements in a Drawing document. From now on, These elements will be called GenItem. |
This use case is intended to show you how to access to a GenItem elements in generative view.
[Top]
CAADrwGeomAccess is a use case of the CAADraftingInterfaces.edu framework that illustrates DraftingInterfaces framework capabilities.
[Top]
Fig. 1 represents the Drawing document on which a front view has been created from a Part document. The document is not provided with the use case.
Fig. 2 represents the Drawing document modified by the use case program:
[Top]
To launch CAADrwGeomAccess, you will need to set up the build time environment, then compile CAADrwGeomAccess along with its prerequisites, set up the run time environment, and then execute the use case [1].
When you launch the use case, pass the full pathname of the Drawing file as argument. A Drawing file is deliverry in the following path: CAADraftingInterfaces.edu\FunctionTests\InputData\DrawingForGenGeomAccessUseCase.CATDrawing.
e:> mkrun -c cmd CAADrwGeomAccess c:\...\DrawingForGenGeomAccessUseCase.CATDrawing c:\DrawingTestOutput.CATDrawing |
$ mkrun -c cmd CAADrwGeomAccess /u/users/.../DrawingForGenGeomAccessUseCase.CATDrawing /u/users/DrawingTestOutput.CATDrawing |
[Top]
The CAADrwGeomAccess use case is made of a single source file named CAADrwGeomAccess.cpp located in the CAADrwGeomAccess.m module of the CAADraftingInterfaces.edu framework:
Windows | InstallRootDirectory\CAADraftingInterfaces.edu\CAADrwGeomAccess.m\ |
Unix | InstallRootDirectory/CAADraftingInterfaces.edu/CAADrwGeomAccess.m/ |
where InstallRootDirectory
is the directory where the CAA CD-ROM
is installed.
[Top]
There are six steps in CAADRWGeomAccess:
[Top]
int main(int iArgc, // Number of arguments (1) char** iArgv) // Path to the new *.CATDrawing document { // Check arguments if(3 != iArgc) return 1; const char *fileName = iArgv[1]; const char *fileNameOut = iArgv[2]; // CREATE SESSION // ================== CATSession *pSampleSession = NULL; HRESULT hr = ::Create_Session("SampleSession",pSampleSession); if (FAILED(hr)) return 1; ... |
This section represents the usual sequence for loading a CATIA document [2].
[Top]
... CATDocument* pDoc = NULL; if (!SUCCEEDED(CATDocumentServices::OpenDocument(fileName, pDoc))) { // Ends session ::Delete_Session("SampleSession"); return 2; } // 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 1; ... |
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 are working in front view of the current sheet CATISheet_var spSheet = piDrawing->GetCurrentSheet(); piDrawing->Release(); piDrawing=NULL; CATIDftSheet *piSheet = NULL; CATIDftView *piCurrentView = NULL; if (SUCCEEDED(spSheet->QueryInterface(IID_CATIDftSheet,(void**) & piSheet) ) ) { piSheet->GetDefaultActiveView (&piCurrentView); piSheet->Release(); piSheet=NULL; } ... |
A drawing may contain several sheets, but only one is current at a time. 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 don’t need to care about releasing them. The drawing variable is a pointer to CATIDrawing, so we have to release when it's no longer used.
[Top]
... CATIView_var spCurrentView = spSheet->GetCurrentView(); CATILinkableObject_var spLink; CATDocument* pDocPart = NULL; if (NULL_var != spCurrentView) spLink = spCurrentView->GetDoc(); if (NULL_var != spLink) pDocPart = spLink->GetDocument(); if (pDocPart) { CATInit_var spInitOnDoc(pDocPart); if(NULL_var == spInitOnDoc) return 5; // Retrieves the root container CATIPrtContainer * piPrtCont = (CATIPrtContainer*) spInitOnDoc->GetRootContainer("CATIPrtContainer"); if (!piPrtCont) { // Ends session ::Delete_Session("SampleSession"); return 6; } // Get the part feature of the container. CATIPrtPart_var spPart = piPrtCont->GetPart(); piPrtCont->Release(); piPrtCont=NULL; } ... |
A link is created between a generative view and the CATPart document
associated to keep the 2D/3D associativity. So, we have to load the
CATPart document from this link.
[Top]
... CATIDftGenGeomAccess *piGenGeomAccess = NULL; IUnknown *piGenView = NULL; if (NULL != piCurrentView) { if (SUCCEEDED( piCurrentView->GetApplicativeExtension(IID_CATIDftGenView,&piGenView))) { if (SUCCEEDED( piGenView->QueryInterface(IID_CATIDftGenGeomAccess, (void**) & piGenGeomAccess) ) ) { CATIUnknownList * piList = NULL; // Get a list containing all Generated Geometry of the view. if( SUCCEEDED( piGenGeomAccess->GetAllGeneratedItems(IID_CATIDftGenGeom, &piList) ) ) { unsigned int piListSize = 0; piList->Count(&piListSize); CATIDftGenGeom * piGenGeom = NULL; IUnknown * item = NULL; CATUnicodeString PartName; CATIVisProperties *piVisProp = NULL; CATVisPropertiesValues ioValues; CATVisPropertyType iPropertyType = CATVPColor; // Loop on all Generated Geometry of the view. for(unsigned int i=0 ; i<piListSize ; i++) { if( SUCCEEDED( piList->Item(i, &item) ) ) { if(SUCCEEDED( item->QueryInterface(IID_CATIDftGenGeom, (void**) & piGenGeom) ) ) { CATCurve * Curve = NULL; if (SUCCEEDED(piGenGeom->GetUnderlyingGeometry(&Curve))) { // Color modification if(SUCCEEDED( piGenGeom->QueryInterface(IID_CATIVisProperties, (void**) & piVisProp) ) ) { CATBoolean cutInfo = FALSE; if (SUCCEEDED(piGenGeom->IsCut(&cutInfo))) { // Red color is applied for generated geometry coming from section if (cutInfo) ioValues.SetColor( 255,0,0); // Greeen color is applied for generated geometry coming from projection else ioValues.SetColor( 0,255,0); piVisProp->SetPropertiesAtt( ioValues, iPropertyType, CATVPLine); } piVisProp->Release(); piVisProp=NULL; } Curve->Release(); Curve = NULL; } // Memory clean piGenGeom->Release(); piGenGeom = NULL; item->Release(); item = NULL; } } } // Memory clean piList->Release(); piList = NULL; } // Memory clean piGenGeomAccess->Release(), piGenGeomAccess = NULL; } // Memory clean piGenView->Release() , piGenView=NULL; } // Memory clean piCurrentView->Release() , piCurrentView=NULL; } ... |
Note:
[Top]
... // Save the result rc = CATDocumentServices::SaveAs(*pDoc, (char *)fileName); ... // Check rc rc = CATDocumentServices::Remove (*pDoc); ... // Check rc // Ends session and drops document rc = ::Delete_Session("SampleSession"); ... // Check rc return 0; } |
This section represents the usual sequence for saving a newly created CATIA document [3].
[Top]
This use case shows the way to :
[Top]
[1] | Building and Lauching CAA V5 Samples |
[2] | Load an existing Document |
[3] | Modifying Object Graphical Properties |
[Top] |
Version: 1 [Dec 2002] | Document created |
[Top] |
Copyright © 2002, Dassault Systèmes. All rights reserved.