Graphics
This section covers the VB API Graphics including displaying lists, displaying text and using the mouse.
Overview
The methods described in this section allow you to draw temporary graphics in a display window. Methods that are identified as 2D are used to draw entities (arcs, polygons, and text) in screen coordinates. Other entities may be drawn using the current model’s coordinate system or the screen coordinate system’s lines, circles, and polylines. Methods are also included for manipulating text properties and accessing mouse inputs.
Getting Mouse Input
The following methods are used to read the mouse position in screen coordinates with the mouse button depressed. Each method outputs the position and an enumerated type description of which mouse button was pressed when the mouse was at that position. These values are contained in the interface IpfcMouseStatus.
The enumerated values are defined in EpfcMouseButton and are as follows:
•  EpfcMOUSE_BTN_LEFT
•  EpfcMOUSE_BTN_RIGHT
•  EpfcMOUSE_BTN_MIDDLE
•  EpfcMOUSE_BTN_LEFT_DOUBLECLICK
Methods Introduced:
  • IpfcSession.UIGetNextMousePick()
  • IpfcSession.UIGetCurrentMouseStatus()
  • The method IpfcSession.UIGetNextMousePick() returns the mouse position when you press a mouse button. The input argument is the mouse button that you expect the user to select.
    The method IpfcSession.UIGetCurrentMouseStatus() returns a value whenever the mouse is moved or a button is pressed. With this method a button does not have to be pressed for a value to be returned. You can use an input argument to flag whether or not the returned positions are snapped to the window grid.
    Drawing a Mouse Box
    This method allows you to draw a mouse box.
    Method Introduced:
  • IpfcSession.UIPickMouseBox()
  • The method IpfcSession.UIPickMouseBox() draws a dynamic rectangle from a specified point in screen coordinates to the current mouse position until the user presses the left mouse button. The return value for this method is of the type IpfcOutline3D.
    You can supply the first corner location programmatically or you can allow the user to select both corners of the box.
    Displaying Graphics
    All the methods in this section draw graphics in the Creo Parametric current window and use the color and linestyle set by calls to IpfcBaseSession.SetStdColorFromRGB() and IpfcBaseSession.SetLineStyle(). The methods draw the graphics in the Creo Parametric graphics color. The default graphics color is white.
    The methods in this section are called using the interface IpfcDisplay. This interface is extended by the IpfcBaseSession interface. This architecture allows you to call all these methods on any IpfcSession object.
    Methods Introduced:
  • IpfcDisplay.SetPenPosition()
  • IpfcDisplay.DrawLine()
  • IpfcDisplay.DrawPolyline()
  • IpfcDisplay.DrawCircle()
  • IpfcDisplay.DrawArc2D()
  • IpfcDisplay.DrawPolygon2D()
  • The method IpfcDisplay.SetPenPosition() sets the point at which you want to start drawing a line. The function IpfcDisplay.DrawLine() draws a line to the given point from the position given in the last call to either of the two functions. Call IpfcDisplay.SetPenPosition() for the start of the polyline, and IpfcDisplay.DrawLine() for each vertex. If you use these methods in two-dimensional modes, use screen coordinates instead of solid coordinates.
    The method IpfcDisplay.DrawCircle() uses solid coordinates for the center of the circle and the radius value. The circle will be placed to the XY plane of the model.
    The method IpfcDisplay.DrawPolyline() also draws polylines, using an array to define the polyline.
    In two-dimensional models the Display Graphics methods draw graphics at the specified screen coordinates.
    The method IpfcDisplay.DrawPolygon2D() draws a polygon in screen coordinates. The method IpfcDisplay.DrawArc2D()draws an arc in screen coordinates.
    Controlling Graphics Display
    Properties Introduced:
  • IpfcDisplay.CurrentGraphicsColor
  • IpfcDisplay.CurrentGraphicsMode
  • The property IpfcDisplay.CurrentGraphicsColor returns the Creo Parametric standard color used to display graphics. The Creo Parametric default is EpfcCOLOR_DRAWING (white).
    The property IpfcDisplay.CurrentGraphicsMode returns the mode used to draw graphics:
    •  EpfcDRAW_GRAPHICS_NORMALCreo Parametric draws graphics in the required color in each invocation.
    •  EpfcDRAW_GRAPHICS_COMPLEMENTCreo Parametric draws graphics normally, but will erase graphics drawn a second time in the same location. This allows you to create rubber band lines.
    Example Code: Creating Graphics On Screen
    The sample code in the file pfcGraphicsExamples.vb located at <creo_vbapi_loadpoint>/vbapi_examples demonstrates the use of mouse-tracking methods to draw graphics on the screen. The static method DrawRubberbandLine prompts the user to pick a screen point. The example uses the ‘complement mode’ to cause the line to display and erase as the user moves the mouse around the window.
    Note
    This example uses the method transformPosition to convert the coordinates into the 3D coordinate system of a solid model, if one is displayed.
    Displaying Text in the Graphics Window
    Method Introduced:
  • IpfcDisplay.DrawText2D()
  • The method IpfcDisplay.DrawText2D() places text at a position specified in screen coordinates. If you want to add text to a particular position on the solid, you must transform the solid coordinates into screen coordinates by using the view matrix.
    Text items drawn are not known to Creo Parametric and therefore are not redrawn when you select View, Repaint. To notify theCreo Parametric of these objects, create them inside the OnDisplay() method of the Display Listener.
    Controlling Text Attributes
    Properties Introduced:
  • IpfcDisplay.extHeight
  • IpfcDisplay.WidthFactor
  • IpfcDisplay.RotationAngle
  • IpfcDisplay.SlantAngle
  • These properties control the attributes of text added by calls to IpfcDisplay.DrawText2D().
    You can access the following information:
    •  Text height (in screen coordinates)
    •  Width ratio of each character, including the gap, as a proportion of the height
    •  Rotation angle of the whole text, in counterclockwise degrees
    •  Slant angle of the text, in clockwise degrees
    Controlling Text Fonts
    Methods and Properties Introduced:
  • IpfcDisplay.DefaultFont
  • IpfcDisplay.CurrentFont
  • IpfcDisplay.GetFontById()
  • IpfcDisplay.GetFontByName()
  • The property IpfcDisplay.DefaultFont returns the default Creo Parametric text font. The text fonts are identified in Creo Parametric by names and by integer identifiers. To find a specific font, use the methods IpfcDisplay.GetFontById() or IpfcDisplay.GetFontByName().
    Display Lists and Graphics
    When generating a display of a solid in a window, Creo Parametric maintains two display lists. A display list contains a set of vectors that are used to represent the shape of the solid in the view. A 3D display list contains a set of three-dimensional vectors that represent an approximation to the geometry of the edges of the solid. This list gets rebuilt every time the solid is regenerated.
    A 2D display list contains the two-dimensional projections of the edges of the solid 3D display list onto the current window. It is rebuilt from the 3D display list when the orientation of the solid changes. The methods in this section enable you to add your own vectors to the display lists, so that the graphics will be redisplayed automatically by Creo Parametric until the display lists are rebuilt.
    When you add graphics items to the 2D display list, they will be regenerated after each repaint (when zooming and panning) and will be included in plots created by Creo Parametric. When you add graphics to the 3D display list, you get the further benefit that the graphics survive a change to the orientation of the solid and are displayed even when you spin the solid dynamically.
    Methods Introduced:
  • IpfcDisplayListener.OnDisplay()
  • IpfcDisplay.CreateDisplayList2D()
  • IpfcDisplay.CreateDisplayList3D()
  • IpfcDisplayList2D.Display()
  • IpfcDisplayList3D.Display()
  • IpfcDisplayList2D.Delete()
  • IpfcDisplayList3D.Delete()
  • A display listener is a class that acts similarly to an action listener. You must implement the method inherited from the IpfcDisplayListener interface. The implementation should provide calls to methods on the provided IpfcDisplay object to produce 2D or 3D graphics.
    In order to create a display list in Creo Parametric, you call IpfcDisplay.CreateDisplayList2D or IpfcDisplay.CreateDisplayList3D() to tell Creo Parametric to use your listener to create the display list vectors.
    IpfcDisplayList2D.Display() or IpfcDisplayList3D.Display() will display or redisplay the elements in your display list. The application should delete the display list data when it is no longer needed.
    The method IpfcDisplayList2D.Delete() and the method IpfcDisplayList3D.Delete() will remove both the specified display list from a session.
    Note
    The method IpfcWindow.Refresh() does not cause either of the display lists to be regenerated, but simply repaints the window using the 2D display list.
    Exceptions
    Possible exceptions that might be thrown by displaying graphics methods are shown in the following table:
    Exception
    Reason
    IpfcXToolkitNotExist
    The display list is empty.
    IpfcXToolkitNotFound
    The function could not find the display list or the font specified in a previous call to IpfcDisplay.CurrentFont was not found.
    IpfcXToolkitCantOpen
    The use of display lists is disabled.
    IpfcXToolkitAbort
    The display was aborted.
    IpfcXToolkitNotValid
    The specified display list is invalid.
    IpfcXToolkitInvalidItem
    There is an invalid item in the display list.
    IpfcXToolkitGeneralError
    The specified display list is already in the process of being displayed.
    Example Code
    The sample code in the file pfcGraphicsExamples.vb located at <creo_vbapi_loadpoint>/vbapi_examples demonstrates the use of IpfcDisplay methods with 3D display lists. The static method AddCircleDisplay() creates a new 3D display list whose graphics are generated by the code in the OnDisplay() method of the Display Circles class. This display list places circles at all of the vertices of a part model on the screen.