Machining

NC Review

Displaying a Distance between Two Points Belonging to the Same Tool Path

Manipulating a tool path
Use Case

Abstract

This article discusses the CAAMfgTPEDisplayDistanceCom use case .

What You Will Learn With This Use Case

This use case is intended to help you manipulate the tool path structure. This involves the following:

[Top]

The CAAMfgTPEDisplayDistanceCom Use Case

CAAMfgTPEDisplayDistanceCom is a use case of the CAAToolPathEditorItf.edu framework that illustrates ToolPathEditor framework capabilities.

[Top]

What Does CAAMfgTPEDisplayDistanceCom Do

CAAMfgTPEDisplayDistanceCom runs with the document CAAMfgToolPath.CATPart shown on Fig.1.

Fig. 1: The tool path of a sweeping operation

[Top]

How to Launch CAAMfgTPEDisplayDistanceCom

To launch CAAMfgTPEDisplayDistanceCom, you will need to:

# Decomment this line in file ToolPathEditor.edu.dico to run CAAMfgTPEAddToolBar Sample
# CAAMfgTPEM3xAddin CATISmgProgramAddin libCAAMfgTPEAddToolBar

[Top]

Where to Find the CAAMfgTPEDisplayDistanceCom Code

The CAAMfgTPEDisplayDistanceCom use case is made of a class named CAAMfgTPEDisplayDistanceCom located in the CAAMfgTPEAddToolBar.m module of the CAAToolPathEditorItf.edu framework:

Windows InstallRootDirectory\CAADoc\CAAToolPathEditorItf.edu\CAAMfgTPEAddToolBar.m
Unix InstallRootDirectory/CAADoc/CAAToolPathEditorItf.edu/CAAMfgTPEAddToolBar.m

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

[Top]

Step-by-Step

There are four logical steps in CAAMfgTPEDisplayDistanceCom:

  1. Creating a Command for Displaying the Distance between Two Points
  2. Selecting a Tool Path
  3. Selecting Two Points
  4. Displaying the Distance between These Two Points

We now comment each of those sections by looking at the code.

[Top]

Creating a Command for Displaying the Distance between Two Points

The class that will implement the command is named CAAMfgTPEDisplayDistanceCom.
Create the CAAMfgTPEDisplayDistanceCom class header file:

class ExportedByCAAMfgTPEAddToolBar CAAMfgTPEDisplayDistanceCom : public CATStateCommand
{
  public:
    DeclareResource (CAAMfgTPEDisplayDistanceCom,CATStateCommand)
    CAAMfgTPEDisplayDistanceCom (CATString* argument);
    virtual ~CAAMfgTPEDisplayDistanceCom();
    void BuildGraph();
    void Valuate (const CATBaseUnknown_var& iValue);  
  private:
    // to Create the rep of the tool path
    void CreateController();
    // Delete the rep of the tool path
    void DeleteController();
    // To update the rep of the tool path
    void DispatchInfo();
    // To get the tool path
    boolean GetSelection (void* data);
    // To Terminate the command
    boolean End (void* data);
    // To display the distance between two points.
    void DisplayDistance();
    // To create the selector of points
    void SetSelector();
    // Processing of events.
    void PreActivate (CATCommand*, CATNotification*, CATCommandClientData);
    void Move (CATCommand*, CATNotification*, CATCommandClientData);
    void EndPreActivate (CATCommand*, CATNotification*, CATCommandClientData);
    // To process the selection of a point.
    void ActivateSelector (CATCommand*, CATNotification*, CATCommandClientData);
    // To remove the rep of the distance.
    void RemoveDistanceRep();
    //  To remove the rep of the point.
    void RemovePointRep();
    // To convert a length in the current unit.
    void ConvertLengthInUnit(double iLength, CATUnicodeString& ioLengthinUnit);
    CATIMfgToolPath_var _ToolPath;
    CAT3DViewer*         _Viewer;
    CATPathElementAgent* _TPSelectionAgent;
    CATDialogAgent*      _TPEndAgent ;
    CAT3DCustomRep*      _DistanceRep;
    CATMathPoint _FirstPoint, _SecondPoint;
    CATPathElement* _ToolPahVisu;
    IID*            _iid;
    CATVisManager*  _VisuManager;
    CAT3DPointRep*  _CurrentPointRep;
    CATSelector*    _Selector;    
    
    double _Distance;
    boolean _hasFirstPoint, _hasSecondPoint;  
};

The CAAMfgTPEDisplayDistanceCom class C++-derives from CATStateCommand. The DeclareResource macro declares that the resource file is CAAMfgTPEDisplayDistanceCom.CATNls. The class has a constructor, a destructor, a DisplayDistance method to compute the distance, severals methods to manage the user's interaction and the rep of the tool path, and a copy constructor.

[Top]

Selecting a Tool Path

First you have to implement the method BuilGraph, which will provide you with capturing the user's interactions.

void CAAMfgTPEDisplayDistanceCom::BuildGraph()
{  
  // To Select tool path.
  _TPSelectionAgent = new CATPathElementAgent("ToolPathSelection");
  if (NULL != _TPSelectionAgent) {
    _TPSelectionAgent->SetOrderedElementType(CATIMfgCompoundTraject::ClassName());
    _TPSelectionAgent->SetBehavior(CATDlgEngWithPrevaluation|CATDlgEngWithCSO|CATDlgEngMultiAcquisition);
    AddCSOClient(_TPSelectionAgent);
  }
  // To terminate the command
  if ( _TPEndAgent == NULL ) {
    _TPEndAgent = new CATDialogAgent("End");
    if (NULL != _TPEndAgent)
      _TPEndAgent->AcceptOnNotify(NULL, CATEdit::ClassName());
  }
  CATDialogState* firstState = GetInitialState("TPESelectToolPath");
  if (NULL != firstState) firstState->AddDialogAgent(_TPSelectionAgent); 
  CATDialogState* secondState = AddDialogState("TPEEndCommand");
  if (NULL != secondState)
    secondState->AddDialogAgent(_TPEndAgent); 
  CATDialogTransition * firstTransition = 
    AddTransition (firstState, secondState,
                   IsOutputSetCondition(_TPSelectionAgent),
                   Action((ActionMethod) &CAAMfgTPEDisplayDistanceCom::GetSelection));
    AddTransition (secondState, NULL,
                   IsOutputSetCondition(_TPEndAgent),
                   Action((ActionMethod) &CAAMfgTPEDisplayDistanceCom::End));
}

Now the method GetSelection is implemented. It gets the selected tool path.

boolean CAAMfgTPEDisplayDistanceCom::GetSelection (void* data)
{ 
  CATBoolean RESULT = CATFalse;
  CATSO* selectedObjects = NULL;
  if (NULL != _TPSelectionAgent)
    selectedObjects = _TPSelectionAgent->GetListOfValues();
  // We display only one tool path in this command
  if ( selectedObjects ) {
    if ( selectedObjects->GetSize() == 1 ) {
      CATPathElement* pathElement=NULL;
      CATIMfgCompoundTraject* ptrCTraject=NULL;
      CATIMfgCompoundTraject_var itfCmpTraject;
      pathElement = (CATPathElement*) (*selectedObjects)[0];
      if (NULL != pathElement) {
        // A CATIMfgCOmpoundTraject must have been seletecd
        ptrCTraject = (CATIMfgCompoundTraject *) (pathElement->FindElement(CATIMfgCompoundTraject::ClassId()));
        itfCmpTraject = ptrCTraject;
        if (!! itfCmpTraject ) {
          _ToolPath = itfCmpTraject;
          ptrCTraject->Release();
          ptrCTraject=NULL;
          RESULT = CATTrue;
        }
        
        pathElement=NULL;
      }
      // Display the tool path.
      CreateController();
      DispatchInfo();
      // To Select points.
      SetSelector();
    }
  }
  return RESULT;
}

First, we verify that the selected object is a tool path object, then we display it ( call to methods CreateController to create the image then a call to method DispatchInfo to display it in the 3d viewer). Then we create a selector to select points on a tool path.

void CAAMfgTPEDisplayDistanceCom::SetSelector() 
{
  // To get the rep of the points
  CATRep* pointsRep=NULL;          
  CATIMfg3DToolPathVisuData_var VisuData (_ToolPath);
  if (!! VisuData)
    VisuData->GetPointsRep(&pointsRep);
  if ( _Selector == NULL ) {
    _Selector = new CATSelector (this,"ToolPathSelector", pointsRep);
    AddAnalyseNotificationCB ( _Selector,
                               _Selector->GetCATPreactivate(),
                               (CATCommandMethod)&CAAMfgTPEDisplayDistanceCom::PreActivate,NULL);
    AddAnalyseNotificationCB ( _Selector,
                               _Selector->GetCATActivate(),
                               (CATCommandMethod)&CAAMfgTPEDisplayDistanceCom::ActivateSelector,NULL);
    AddAnalyseNotificationCB ( _Selector,
                               _Selector->GetCATMove(),
                               (CATCommandMethod)&CAAMfgTPEDisplayDistanceCom::Move,NULL);
    AddAnalyseNotificationCB ( _Selector,
                               _Selector->GetCATEndPreactivate(),
                               (CATCommandMethod)&CAAMfgTPEDisplayDistanceCom::EndPreActivate,NULL);
  }
  else {
    _Selector->AssociateToRep(pointsRep);
  }
}

[Top]

Selecting Two Points

The method Activateselector is called when an end-user click on a point of the tool path.

void CAAMfgTPEDisplayDistanceCom::ActivateSelector(CATCommand* c1, CATNotification* c2, CATCommandClientData c3)
{
  CATGraphicElementIntersection* Intersection = NULL;
  if (NULL != _Selector)  {
    Intersection = (CATGraphicElementIntersection*) 
            _Selector->SendCommandSpecificObject (CATGraphicElementIntersection::ClassName(), c2);
  }
  if (!Intersection) return;
  if ( _hasFirstPoint) {
    _hasSecondPoint = CATTrue;
    _SecondPoint = Intersection->point;
    _Distance = _FirstPoint.DistanceTo(_SecondPoint);
    DisplayDistance ();
    _hasFirstPoint = CATFalse;
  }
  else {
    _hasFirstPoint = CATTrue;
    _FirstPoint = Intersection->point;
    _Distance = _FirstPoint.DistanceTo(_SecondPoint);
    if ( _hasSecondPoint) {
      DisplayDistance ();
      _hasSecondPoint = CATFalse;
    }
  }
  Intersection->Release();
  if ( _Viewer) _Viewer->Draw();
}

[Top]

Displaying the Distance between These Two Points

The next is to compute distance between two selected points and to display this information in the 3d viewer.

void CAAMfgTPEDisplayDistanceCom::DisplayDistance()
{
  if ( _hasFirstPoint &&  _hasSecondPoint ) {
    RemoveDistanceRep();
    CATUnicodeString distanceStr;
    ConvertLengthInUnit(_Distance, distanceStr);
    float tab[3] = {(float)_SecondPoint.GetX(),(float)_SecondPoint.GetY(),(float)_SecondPoint.GetZ()};
    CAT3DMarkerGP* arrowGP = new CAT3DMarkerGP(tab,1,FILLED_ARROW);
    CATMathPointf anchor=(_FirstPoint+ _SecondPoint)/2.0;
    CAT3DAnnotationTextGP* textGP  = new CAT3DAnnotationTextGP(anchor,distanceStr,BASE_CENTER);
    float Points[6] = {  (float)_FirstPoint.GetX(), (float)_FirstPoint.GetY(), (float)_FirstPoint.GetZ(),
                         (float)_SecondPoint.GetX(), (float)_SecondPoint.GetY(),(float)_SecondPoint.GetZ()};
    CAT3DLineGP* lineGP = new CAT3DLineGP (Points);
    CATGraphicAttributeSet AttributsDir;
    AttributsDir.SetColor(RED);
    _DistanceRep = new CAT3DCustomRep(lineGP,AttributsDir);
    if (NULL != _DistanceRep) {
      _DistanceRep -> AddGP(textGP,AttributsDir);
      _DistanceRep -> AddGP(arrowGP,AttributsDir);
    }
    if (_Viewer) {
      _Viewer->AddRep(_DistanceRep);
      _Viewer->Draw();
    }
  }
}

[Top]


In Short

This article provides an example on how to use the structure of the tool path and how to make command in the tool path editor. It shows how to select points a on a tool path.

[Top]


References

[1] Building and Launching a CAA V5 Use Case
[2] Dump of Tool Path Content Command
[Top]

History

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

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