catdrawing get link part/Editing Generated Geometry in a Generative View

Mechanical Design

Drafting

Editing Generated Geometry in a Generative View

How to access generated geometry
Use Case

Abstract

This 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.

  • What You Will Learn With This Use Case
  • The CAADrwGeomAccess Use Case
    • What Does CAADrwGeomAccess Do
    • How to Launch CAADrwGeomAccess
    • Where to Find the CAADrwGeomAccess Code
  • Step-by-Step
  • In Short
  • References

What You Will Learn With This Use Case

This use case is intended to show you how to access to a GenItem elements in generative view.

[Top]

The CAADrwGeomAccess Use Case

CAADrwGeomAccess is a use case of the CAADraftingInterfaces.edu framework that illustrates DraftingInterfaces framework capabilities.

[Top]

What Does CAADrwGeomAccess Do?

Fig. 1: Initial Document

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 The Document modified by the Use Case

Fig. 2 represents the Drawing document modified by the use case program:

  • The red color has be been applied to all GenItem elements generated by the section plane.
  • The green color has been applied to all GenItem elements generated by the projection.

[Top]

How to Launch CAADrwGeomAccess

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.

  • With Windows
    e:> mkrun -c cmd
    CAADrwGeomAccess c:\...\DrawingForGenGeomAccessUseCase.CATDrawing c:\DrawingTestOutput.CATDrawing
  • With UNIX
    $ mkrun -c cmd
    CAADrwGeomAccess /u/users/.../DrawingForGenGeomAccessUseCase.CATDrawing  /u/users/DrawingTestOutput.CATDrawing

[Top]

Where to Find the CAADrwGeomAccess Code

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:

WindowsInstallRootDirectory\CAADraftingInterfaces.edu\CAADrwGeomAccess.m\
UnixInstallRootDirectory/CAADraftingInterfaces.edu/CAADrwGeomAccess.m/

where InstallRootDirectory is the directory where the CAA CD-ROM is installed.

[Top]

Step-by-Step

There are six steps in CAADRWGeomAccess:

  1. Creating and Initializing the Document
  2. Accessing the Drawing in the Document
  3. Navigating through the Drawing and Get the current View
  4. Getting the Part document pointed by the Current View
  5. Reading and Coloring the Generated Geometry in the Current View
  6. Saving the Document and Exiting

[Top]

Creating and Initializing the Document

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]

Accessing the Drawing in the Document

...
  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]

Navigating through the Drawing and Sheet to Get the Current View

...
  // 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]

Getting the Part Document Pointed by Current View

...
   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]

Reading and Coloring the Generated Geometry in the Current View  

...
  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: 

  1. Color modification is done by using CATIVisProperties interface capabilities [4].
  2. These modifications are not kept after view update process because GenItem elements are deleted and recreated.

[Top]

Saving the Document and Exiting

...
  // 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]


In Short

This use case shows the way to :

  1. Open a Drawing document.
  2. Get the current view.
  3. Get the Part Document pointed by the generative view and open it.
  4. Scan all the generated geometry of the view.
  5. Modify the color of the aggregated curve to the GenItem elements by using CATVisProperties interfaces.

[Top]


References

[1]Building and Lauching CAA V5 Samples
[2]Load an existing Document
[3]Modifying Object Graphical Properties
[Top]

History

Version: 1 [Dec 2002]Document created
[Top]

Copyright © 2002, Dassault Systèmes. All rights reserved.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值