Windows and Views
Creo Object TOOLKIT C++ provides access to Creo windows and saved views. This section describes the methods that provide this access.
Windows
This section describes the Creo Object TOOLKIT C++ methods that access Window objects. The topics are as follows:
Getting a Window Object
Methods Introduced:
The method pfcBaseSession::GetCurrentWindow provides access to the current active window in Creo application.
The method pfcBaseSession::CreateModelWindow creates a new window that contains the model that was passed as an argument.
Note
You must call the method pfcModel::Display for the model geometry to be displayed in the window.
Use the method pfcBaseSession::ListWindows to get a list of all the current windows in session.
The method pfcBaseSession::GetWindow gets the handle to a window given its integer identifier.
The method pfcBaseSession::OpenFile returns the handle to a newly created window that contains the opened model.
Note
If a model is already open in a window the method returns a handle to the window.
The method pfcBaseSession::GetModelWindow returns the handle to the window that contains the opened model, if it is displayed.
Creating Windows
Method Introduced:
In Creo application, when the main window is active, you can open an accessory window for operations such as editing an inserted component or a feature, previewing an object, selecting a reference, and so on. The model tree associated with this Creo object is also displayed in the accessory window.
Use the method wfcWSession::CreateAccessorywindowWithTree to open an accessory window containing the specified object. If a window is already open with the specified object, the method returns the identifier of that window. If an empty window is already open, the method uses this window to open the object. The input argument EnableTree controls the display of the model tree in the accessory window. If set to true the model tree is displayed in the accessory window.
Note
The accessory window has restricted menu options and does not have any toolbar.
The method wfcWSession::CreateBarewindow opens a window containing the specified object. If a window is already open with the specified object, the method returns the identifier of that window. If an empty window is already open, the method uses this window to open the object.
Note
The window does not have any menus or toolbar. All the mouse capabilities for a view such as, zoom, rotate and pan are available.
Window Operations
Methods Introduced:
The methods pfcWindow::GetHeight, pfcWindow::GetWidth, pfcWindow::GetXPos, and pfcWindow::GetYPos retrieve the height, width, x-position, and y-position of the window respectively. The values of these parameters are normalized from 0 to 1.
The methods pfcWindow::GetGraphicsAreaHeight and pfcWindow::GetGraphicsAreaWidth retrieve the height and width of the Creo graphics area window without the border respectively. The values of these parameters are normalized from 0 to 1. For both the window and graphics area sizes, if the object occupies the whole screen, the window size returned is 1. For example, if the screen is 1024 pixels wide and the graphics area is 512 pixels, then the width of the graphics area window is returned as 0.5.
The method pfcWindow::Clear removes geometry from the window.
Both pfcWindow::Repaint and pfcWindow::Refresh repaint solid geometry. However, the Refresh method does not remove highlights from the screen and is used primarily to remove temporary geometry entities from the screen.
Use the method pfcWindow::Close to close the window. If the current window is the original window created when Creo application started, this method clears the window. Otherwise, it removes the window from the screen.
Use the method wfcWWindow::Refit to refit the model in the specified window so that the entire model can be viewed.
The method pfcWindow::Activate activates a window. This method is available only in the asynchronous mode.
The method pfcWindow::GetId retrieves the ID of the Creo window.
The method pfcBaseSession::FlushCurrentWindow flushes the pending display commands on the current window.
Note
It is recommended to call this method only after completing all the display operations. Excessive use of this method will cause major slow down of systems running on Windows Vista and Windows 7.
Embedded Browser
Methods Introduced:
The methods pfcWindow::GetURL and pfcWindow::SetURL enables you to find and change the URL displayed in the embedded browser in the Creo window.
The methods pfcWindow::GetBrowserSize and pfcWindow::SetBrowserSize enables you to find and change the size of the embedded browser in the Creo window.
Note
The methods pfcWindow::GetBrowserSize and pfcWindow::SetBrowserSize are not supported if the browser is open in a separate window.
The method wfcBrowser::ExecuteScript executes a Java script on the browser page.
The method wfcBrowser::ExecuteScriptFromFile executes a Java script file on the browser page.
The method wfcBrowser::GetId returns a unique identifier of the browser page.
The method wfcBrowser::GetUrl returns a url of the browser page.
The method wfcBrowser::AddActionListener adds a listener object for browser event callback. The input arguments are:
•  Listener— Specifies the listener which is defined by the class wfcBrowserListener.
•  EventTypes—Specifies the type of the events to listen and is defined by the enumerated data type wfcBrowserEventType. The valid value wfcON_BEFORE_DESTROY specifies the event before destroying the browser window.
Use the method wfcBrowserListener::OnBeforeDestroy to return a callback when an embedded browser is destroyed in Creo. The callback is returned for each page of the browser window.
Views
This section describes the Creo Object TOOLKIT C++ methods that access pfcView objects. The topics are as follows:
Getting a View Object
Methods Introduced:
Any solid model inherits from the interface pfcViewOwner. This will enable you to use these methods on any solid object.
The method pfcViewOwner::RetrieveView sets the current view to the orientation previously saved with a specified name.
Use the method pfcViewOwner::GetView to get a handle to a named view without making any modifications.
The method pfcViewOwner::ListViews returns a list of all the views previously saved in the model.
From Creo Parametric2.0 M120 onward, the method pfcViewOwner::GetCurrentView has been deprecated. The method returns a view handle that represents the current orientation. Although this view does not have a name, you can use this view to find or modify the current orientation.
View Operations
Methods Introduced:
To get the name of a view given its identifier, use the method pfcView::GetName.
The method pfcView::GetIsCurrent determines if the View object represents the current view.
The pfcView::Reset method restores the current view to the default view.
To store the current view under the specified name, call the method pfcViewOwner::SaveView.
Coordinate Systems and Transformations
This section describes the various coordinate systems used by Creo application, which are accessible from Creo Object TOOLKIT C++. It also explains how to transform from one coordinate system to another.
Coordinate Systems
Creo applications and Creo Object TOOLKIT C++ use the following coordinate systems:
The following sections describe each of these coordinate systems.
Solid Coordinate System
The solid coordinate system is the three-dimensional, Cartesian coordinate system used to describe the geometry of a Creo solid model. In a part, the solid coordinate system describes the geometry of the surfaces and edges. In an assembly, the solid coordinate system also describes the locations and orientations of the assembly members.
You can visualize the solid coordinate system in Creo application by creating a coordinate system datum with the option Default. Distances measured in solid coordinates correspond to the values of dimensions as seen by the Creo user.
Solid coordinates are used by Creo Object TOOLKIT C++ for all the methods that look at geometry and most of the methods that draw three-dimensional graphics.
Screen Coordinate System
The screen coordinate system is two-dimensional coordinate system that describes locations in a Creo window. This is an intermediate coordinate system after which the screen points are transformed to screen pixels. All the models are first mapped to the screen coordinate system. When the user zooms or pans the view, the screen coordinate system follows the display of the solid, so a particular point on the solid always maps to the same screen coordinate. The mapping changes only when the view orientation is changed.
Screen coordinates are used by some of the graphics methods, the mouse input methods, and all methods that draw graphics or manipulate items on a drawing.
Window Coordinate System
The window coordinate system is similar to the screen coordinate system. After mapping the models to the screen coordinate system, they are mapped to the window coordinate before being drawn to screen pixels based on screen resolution. When pan or zoom values are applied to the coordinates in the screen coordinate system, they result in window coordinates. When an object is first displayed in a window, or the option View  Refit is used, the screen and window coordinates are the same.
Window coordinates are needed only if you need to take account of zoom and pan—for example, to find out whether a point on the solid is visible in the window, or to draw two-dimensional text in a particular window location, regardless of pan and zoom.
Drawing Coordinate System
The drawing coordinate system is a two-dimensional system that describes the location on a drawing relative to the bottom, left corner, and measured in drawing units. For example, on a U.S. letter-sized, landscape-format drawing sheet that uses inches, the top, right-corner is (11, 8.5) in drawing coordinates.
The Creo Object TOOLKIT C++ methods and properties that manipulate drawings generally use screen coordinates.
Drawing View Coordinate System
The drawing view coordinate system is used to describe the locations of entities in a drawing view.
Assembly Coordinate System
An assembly has its own coordinate system that describes the positions and orientations of the member parts, subassemblies, and the geometry of datum features created in the assembly.
When an assembly is retrieved into memory each member is also loaded and continues to use its own solid coordinate system to describe its geometry.
This is important when you are analyzing the geometry of a subassembly and want to extract or display the results relative to the coordinate system of the parent assembly.
Datum Coordinate System
A coordinate system datum can be created anywhere in any part or assembly, and represents a user-defined coordinate system. It is often a requirement in a Creo Object TOOLKIT C++ application to describe geometry relative to such a datum.
Section Coordinate System
Every sketch has a coordinate system used to locate entities in that sketch. Sketches used in features will use a coordinate system different from that of the solid model.
Transformations
Methods Introduced:
All coordinate systems are treated in Creo Object TOOLKIT C++ as if they were three-dimensional. Therefore, a point in any of the coordinate systems is always represented by the pfcPoint3D class:
Vectors store the same data but are represented for clarity by the pfcVector3D class.
Screen coordinates contain a z-value whose positive direction is outwards from the screen. The value of z is not generally important when specifying a screen location as an input to a method, but it is useful in other situations. For example, if you select a datum plane, you can find the direction of the plane by calculating the normal to the plane, transforming to screen coordinates, then looking at the sign of the z-coordinate.
A transformation between two coordinate systems is represented by the pfcTransform3D class. This class contains a 4x4 matrix that combines the conventional 3x3 matrix that describes the relative orientation of the two systems, and the vector that describes the shift between them.
The 4x4 matrix used for transformations is as follows:
Image
The utility method pfcTransform3D::Invert inverts a transformation matrix so that it can be used to transform points in the opposite direction.
Creo Object TOOLKIT C++ provides two utilities for performing coordinate transformations. The method pfcTransform3D::TransformPoint transforms a three-dimensional point and pfcTransform3D::TransformVector transforms a three-dimensional vector.
The method pfcMakeMatrixOrthonormal converts a non-orthonormal matrix to an orthonormal matrix with the specified scaling factor. The input arguments follow:
•  Matrix—The matrix to be converted to orthonormal.
•  Scale—Scale factor to be applied on the matrix.
Transforming to Screen Coordinates
Methods Introduced:
The view matrix describes the transformation from solid to screen coordinates. The method pfcView::GetTransform provides the view matrix for a model in the view. The method pfcView::SetTransform allows you to specify the transformation matrix for a model in the view.
To get and set the transformation matrix for a model in the current view, use the methods pfcViewOwner::GetCurrentViewTransform and pfcViewOwner::SetCurrentViewTransform.
The method pfcView::Rotate rotates an object , relative to the X, Y, or Z axis for the specified rotation angle.
To rotate an object in the current view, use the method pfcViewOwner::CurrentViewRotate.
To transform from screen to solid coordinates, invert the transformation matrix using the method pfcTransform3D::Invert.
Transforming to Coordinate System Datum Coordinates
Method Introduced:
The method pfcCoordSystem::GetCoordSys provides the location and orientation of the coordinate system datum in the coordinate system of the solid that contains it. The location is in terms of the directions of the three axes and the position of the origin.
Transforming Window Coordinates
Methods Introduced
You can alter the pan and zoom of a window by using a Screen Transform object. This object contains three attributes. PanX and PanY represent the horizontal and vertical movement. Every increment of 1.0 moves the view point one screen width or height. Zoom represents a scaling factor for the view. This number must be greater than zero.
Transforming Coordinates of an Assembly Member
Method Introduced:
The method pfcComponentPath::GetTransform provides the matrix for transforming from the solid coordinate system of the assembly member to the solid coordinates of the parent assembly, or the reverse.