Graphics
This section covers Creo.JS Graphics including displaying lists, displaying text and using the mouse.
Overview
Use 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 such as arcs, polygons, and text, in screen coordinates. Other entities may be drawn using the coordinate system for the for the current model’s or the lines, circles, and polylines for the screen coordinate. Methods are also included for manipulating text properties and accessing mouse input.
Getting Mouse Input
The following methods are used to read the mouse position in screen coordinates when the mouse button is pressed. 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 class pfcMouseStatus.
The enumerated values are defined in pfcMouseButton and are as follows:
•  MOUSE_BTN_LEFT
•  MOUSE_BTN_RIGHT
•  MOUSE_BTN_MIDDLE
•  MOUSE_BTN_LEFT_DOUBLECLICK
Methods Introduced:
  • pfcSession.UIGetNextMousePick()
  • pfcSession.UIGetCurrentMouseStatus()
  • The method pfcSession.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 pfcSession.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
    Use this method to draw a mouse box.
    Method Introduced:
  • pfcSession.UIPickMouseBox()
  • The method pfcSession.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 pfcOutline3D.
    You can supply the first corner location programmatically or the user can 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 calling pfcBaseSession.SetStdColorFromRGB() and pfcBaseSession.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 classpfcDisplay. This class is extended by the pfcBaseSession class . With this architecture you can call all these methods on any pfcSession object.
    Methods Introduced:
  • pfcDisplay.SetPenPosition()
  • pfcDisplay.DrawLine()
  • pfcDisplay.DrawPolyline()
  • pfcDisplay.DrawCircle()
  • pfcDisplay.DrawArc2D()
  • pfcDisplay.DrawPolygon2D()
  • The method pfcDisplay.SetPenPosition() sets the point at which you want to start drawing a line. The method pfcDisplay.DrawLine() draws a line to the given point from the position given in the last call to either of the two functions. Call pfcDisplay.SetPenPosition() for the start of the polyline, and pfcDisplay.DrawLine() for each vertex. If you use these methods in two-dimensional modes, use screen coordinates instead of solid coordinates.
    The method pfcDisplay.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 pfcDisplay.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 pfcDisplay.DrawPolygon2D() draws a polygon in screen coordinates. The method pfcDisplay.DrawArc2D() draws an arc in screen coordinates.
    Controlling Graphics Display
    Properties Introduced:
  • pfcDisplay.CurrentGraphicsColor
  • pfcDisplay.CurrentGraphicsMode
  • The property pfcDisplay.CurrentGraphicsColor returns the Creo Parametric standard color used to display graphics. The Creo Parametric default is COLOR_DRAWING (white).
    The property pfcDisplay.CurrentGraphicsMode returns the mode used to draw graphics using the enumerated data type pfcGraphicsMode and the valid values are:
    •  DRAW_GRAPHICS_NORMALCreo Parametric draws graphics in the required color in each invocation.
    •  DRAW_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.
    Displaying Text in the Graphics Window
    Method Introduced:
  • pfcDisplay.DrawText2D()
  • The method pfcDisplay.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.
    Controlling Text Attributes
    Properties Introduced:
  • pfcDisplay.TextHeight
  • pfcDisplay.WidthFactor
  • pfcDisplay.RotationAngle
  • pfcDisplay.SlantAngle
  • These properties control the attributes of text added by calling the method pfcDisplay.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
    Properties Introduced:
  • pfcDisplay.DefaultFont
  • pfcDisplay.CurrentFont
  • pfcDisplay.GetFontById()
  • pfcDisplay.GetFontByName()
  • The properties pfcDisplay.DefaultFont and pfcDisplay.CurrentFont return the default Creo Parametric text font and the current font used for text graphics in Creo Parametric, respectively. The text fonts are identified in Creo Parametric by names and by integer identifiers. To find a specific font, use the methods pfcDisplay.GetFontById() or pfcDisplay.GetFontByName().