Visualization Functions¶
The following group of functions allow for the OpenVSP GUI to be manipulated through the API.
|
Low level routine that should be called to set up GUI before running StartGUI() |
|
Launch the interactive OpenVSP GUI. |
Enable Stop GUI Menu Item from the OpenVSP GUI. |
|
Disable Stop GUI Menu Item from the OpenVSP GUI. |
|
|
Stop OpenVSP GUI event loop and hide screens. |
|
Cause OpenVSP to display a popup message. |
Tell OpenVSP that the GUI needs to be updated. |
|
Test if the current OpenVSP build includes graphics capabilities. |
|
|
Obtain the lock on the OpenVSP GUI event loop. |
|
Release the lock on the OpenVSP GUI event loop. |
Test if the OpenVSP GUI event loop is running. |
|
|
Capture the specified screen and save to file. |
|
Toggle viewing the axis |
|
Toggle viewing the border frame |
|
Set the draw type of the specified geometry |
|
Set the wireframe color of the specified geometry |
|
Set the display type of the specified geometry |
|
Set the visualization material the specified geometry |
|
Get the display type of the specified geometry |
|
Get the wireframe color of the specified geometry. |
|
Get the name of the visualization material applied to the specified geometry |
|
Set the visualization material the specified geometry |
Get the names of all visualization materials |
|
Get the number of lights in the model. |
|
|
Get the ID of a light, so that its Parms can be reached the way any other container's are. |
|
Set the background color |
|
Set the view of all viewports |
|
Set the view of a particular viewports |
Fit contents to all viewports |
|
Reset views of all viewports |
|
|
Set the rows and columns of the window layout |
|
Set whether all instances of GUI device type are disabled |
|
Set whether screen is disabled |
|
Set whether geom screen is disabled |
|
Hide an OpenVSP GUI screen |
|
Show an OpenVSP GUI screen |
Details¶
- openvsp.InitGUI()[source]¶
Low level routine that should be called to set up GUI before running StartGUI()
InitGUI()
- openvsp.StartGUI()[source]¶
Launch the interactive OpenVSP GUI. In a multi-threaded environment, this must be called from the main thread only. This starts the GUI event loop. It will also show the main screen and screens displayed when StopGUI() was previously called.
StartGUI()
- openvsp.EnableStopGUIMenuItem()[source]¶
Enable Stop GUI Menu Item from the OpenVSP GUI.
Typically used for the blocking-mode OpenVSP GUI from the API.
This will add a “Stop GUI” option to the file pulldown menu and will also cause the exit button on the window frame to have the same effect. When selected, these options will stop the OpenVSP GUI event loop, returning control to the API program. OpenVSP will not terminate, the model will remain in memory and will be responsive to subsequent API calls.
EnableStopGUIMenuItem() StartGUI()
See also: DisableStopGUIMenuItem
- openvsp.DisableStopGUIMenuItem()[source]¶
Disable Stop GUI Menu Item from the OpenVSP GUI.
This reverses the operation of EnableStopGUIMenuItem.
EnableStopGUIMenuItem() DisableStopGUIMenuItem() StartGUI()
See also: EnableStopGUIMenuItem
- openvsp.StopGUI()[source]¶
Stop OpenVSP GUI event loop and hide screens. Keep OpenVSP running and in memory.
StartGUI() StopGUI() StartGUI()
See also: StartGUI
- openvsp.PopupMsg(msg)[source]¶
Cause OpenVSP to display a popup message.
StartGUI() PopupMsg( "This is a popup message." )
- Parameters:
[in] – msg string Message to display.
- openvsp.UpdateGUI()[source]¶
Tell OpenVSP that the GUI needs to be updated.
StartGUI() pod_id = AddGeom( "POD" ) length = FindParm( pod_id, "Length", "Design" ) SetParmVal( length, 13.0 ) UpdateGUI()
See also: StartGUI
- openvsp.IsGUIBuild()[source]¶
Test if the current OpenVSP build includes graphics capabilities.
if ( IsGUIBuild() ): print( "OpenVSP build is graphics capable." ) else: print( "OpenVSP build is not graphics capable." )
- Return type:
boolean
- Returns:
bool True if the current OpenVSP build includes graphics capabilities. False otherwise.
- openvsp.Lock()[source]¶
Obtain the lock on the OpenVSP GUI event loop. This will prevent the interactive GUI from updating or accepting user input until the lock is released – thereby allowing longer-time commands including analyses to execute without the chance of the OpenVSP state changing during execution.
StartGUI() pod_id = AddGeom( "POD" ) Lock() rid = ExecAnalysis( "CompGeom" ) mesh_id_vec = GetStringResults( rid, "Mesh_GeomID" ) DeleteGeomVec( mesh_id_vec ) Unlock()
See also: Unlock
- openvsp.Unlock()[source]¶
Release the lock on the OpenVSP GUI event loop.
StartGUI() pod_id = AddGeom( "POD" ) Lock() rid = ExecAnalysis( "CompGeom" ) mesh_id_vec = GetStringResults( rid, "Mesh_GeomID" ) DeleteGeomVec( mesh_id_vec ) Unlock()
See also: Lock
- openvsp.IsEventLoopRunning()[source]¶
Test if the OpenVSP GUI event loop is running.
StartGUI() if ( IsEventLoopRunning() ): print( "Event loop is running." )
- Return type:
boolean
- Returns:
bool True if the OpenVSP GUI event loop is running. False otherwise.
- openvsp.ScreenGrab(fname, w, h, transparentBG, autocrop=False)[source]¶
Capture the specified screen and save to file. Note, VSP_USE_FLTK must be defined
screenw = 2000 # Set screenshot width and height screenh = 2000 fname = "test_screen_grab.png" ScreenGrab( fname, screenw, screenh, True, True ) # Take PNG screenshot
- Parameters:
[in] – fname string Output file name
[in] – w int Width of screen grab
[in] – h int Height of screen grab
[in] – transparentBG bool Transparent background flag
[in] – autocrop bool Automatically crop transparent background flag
- openvsp.SetViewAxis(vaxis)[source]¶
Toggle viewing the axis
SetViewAxis( False ) # Turn off axis marker in corner of viewscreen
- Parameters:
[in] – vaxis bool True to show the axis, false to hide the axis
- openvsp.SetShowBorders(brdr)[source]¶
Toggle viewing the border frame
SetShowBorders( False ) # Turn off red/black border on active window
- Parameters:
[in] – brdr bool True to show the border frame, false to hide the border frame
- openvsp.SetGeomDrawType(geom_id, type)[source]¶
Set the draw type of the specified geometry
pid = AddGeom( "POD", "" ) # Add Pod for testing SetGeomDrawType( pid, GEOM_DRAW_SHADE ) # Make pod appear as shaded # The draw type is display state rather than model state, so there is nothing # to read back. What has to hold is that a Geom which does not exist is # rejected. The error queue is reached through the error manager singleton # in Python. err_mgr = ErrorMgrSingleton.getInstance() SetGeomDrawType( "NOSUCHGEOM", GEOM_DRAW_SHADE ) assert err_mgr.GetNumTotalErrors() > 0, "SetGeomDrawType accepted a bad Geom ID" # That error was raised deliberately, so take it back off the queue. while err_mgr.GetNumTotalErrors() > 0 : err = err_mgr.PopLastError()
See also: DRAW_TYPE :param [in]: geom_id string Geom ID :param [in]: type int Draw type enum (i.e. GEOM_DRAW_SHADE)
- openvsp.SetGeomWireColor(geom_id, r, g, b)[source]¶
Set the wireframe color of the specified geometry
pid = AddGeom( "POD", "" ) SetGeomWireColor( pid, 0, 0, 255 ) # The colour is display state rather than model state, so there is nothing to # read back. What has to hold is that a Geom which does not exist is # rejected. The error queue is reached through the error manager singleton # in Python. err_mgr = ErrorMgrSingleton.getInstance() SetGeomWireColor( "NOSUCHGEOM", 0, 0, 255 ) assert err_mgr.GetNumTotalErrors() > 0, "SetGeomWireColor accepted a bad Geom ID" # That error was raised deliberately, so take it back off the queue. while err_mgr.GetNumTotalErrors() > 0 : err = err_mgr.PopLastError()
- Parameters:
[in] – geom_id string Geom ID
[in] – r int Red component of color [0, 255]
[in] – g int Green component of color [0, 255]
[in] – b int Blue component of color [0, 255]
- openvsp.SetGeomDisplayType(geom_id, type)[source]¶
Set the display type of the specified geometry
pid = AddGeom( "POD" ) # Add Pod for testing SetGeomDisplayType( pid, DISPLAY_DEGEN_PLATE ) # Make pod appear as Bezier plate (Degen Geom) # The display type is display state rather than model state, so there is # nothing to read back. What has to hold is that a Geom which does not exist # is rejected. The error queue is reached through the error manager # singleton in Python. err_mgr = ErrorMgrSingleton.getInstance() SetGeomDisplayType( "NOSUCHGEOM", DISPLAY_DEGEN_PLATE ) assert err_mgr.GetNumTotalErrors() > 0, "SetGeomDisplayType accepted a bad Geom ID" # That error was raised deliberately, so take it back off the queue. while err_mgr.GetNumTotalErrors() > 0 : err = err_mgr.PopLastError()
See also: DISPLAY_TYPE :param [in]: geom_id string Geom ID :param [in]: type int Display type enum (i.e. DISPLAY_BEZIER)
- openvsp.GetGeomDrawType(geom_id)[source]¶
Set the visualization material the specified geometry
pid = AddGeom( "POD" ) SetGeomMaterialName( pid, "Ruby" ) # Ruby is one of the materials the library ships with. assert "Ruby" in GetMaterialNames(), "Ruby is not in the material library" # A material that is not in the library has to be rejected. The error queue # is reached through the error manager singleton in Python. err_mgr = ErrorMgrSingleton.getInstance() SetGeomMaterialName( pid, "NoSuchMaterial" ) assert err_mgr.GetNumTotalErrors() > 0, "SetGeomMaterialName accepted an unknown material" # That error was raised deliberately, so take it back off the queue. while err_mgr.GetNumTotalErrors() > 0 : err = err_mgr.PopLastError()
- Parameters:
[in] – geom_id string Geom ID
[in] – name string Material name
Get the draw type of the specified geometry
pid = AddGeom( "POD", "" ) SetGeomDrawType( pid, GEOM_DRAW_SHADE ) assert GetGeomDrawType( pid ) == GEOM_DRAW_SHADE, "GetGeomDrawType did not report the type that was set" SetGeomDrawType( pid, GEOM_DRAW_WIRE ) assert GetGeomDrawType( pid ) == GEOM_DRAW_WIRE, "GetGeomDrawType did not follow a second set"
See also: DRAW_TYPE, SetGeomDrawType :param [in]: geom_id string Geom ID :rtype: int :return: int Draw type enum (i.e. GEOM_DRAW_SHADE)
- openvsp.GetGeomDisplayType(geom_id)[source]¶
Get the display type of the specified geometry
pid = AddGeom( "POD" ) SetGeomDisplayType( pid, DISPLAY_DEGEN_PLATE ) assert GetGeomDisplayType( pid ) == DISPLAY_DEGEN_PLATE, "GetGeomDisplayType did not report the type that was set" SetGeomDisplayType( pid, DISPLAY_BEZIER ) assert GetGeomDisplayType( pid ) == DISPLAY_BEZIER, "GetGeomDisplayType did not follow a second set"
See also: DISPLAY_TYPE, SetGeomDisplayType :param [in]: geom_id string Geom ID :rtype: int :return: int Display type enum (i.e. DISPLAY_BEZIER)
- openvsp.GetGeomWireColor(geom_id)[source]¶
Get the wireframe color of the specified geometry. The color components are returned in the X, Y and Z members of the vector as red, green and blue over the range [0, 255].
pid = AddGeom( "POD", "" ) SetGeomWireColor( pid, 0, 0, 255 ) color = GetGeomWireColor( pid ) assert abs( color.x() ) < 1e-9, "GetGeomWireColor did not report the color that was set" assert abs( color.y() ) < 1e-9, "GetGeomWireColor did not report the color that was set" assert abs( color.z() - 255 ) < 1e-9, "GetGeomWireColor did not report the color that was set" # Each Geom carries its own color. p2id = AddGeom( "POD", "" ) SetGeomWireColor( p2id, 255, 0, 0 ) assert abs( GetGeomWireColor( pid ).z() - 255 ) < 1e-9, "setting one Geom's color disturbed another"
See also: SetGeomWireColor :param [in]: geom_id string Geom ID :rtype:
vec3d:return: vec3d Red, green and blue components of the wireframe color
- openvsp.GetGeomMaterialName(geom_id)[source]¶
Get the name of the visualization material applied to the specified geometry
pid = AddGeom( "POD" ) SetGeomMaterialName( pid, "Ruby" ) assert GetGeomMaterialName( pid ) == "Ruby", "GetGeomMaterialName did not report the material that was set" # The name that comes back has to be one the library knows. assert GetGeomMaterialName( pid ) in GetMaterialNames(), "GetGeomMaterialName reported a material the library does not have"
See also: SetGeomMaterialName, GetMaterialNames :param [in]: geom_id string Geom ID :rtype: string :return: string Material name
- openvsp.AddMaterial(name, ambient, diffuse, specular, emissive, alpha, shininess)[source]¶
Set the visualization material the specified geometry
pid = AddGeom( "POD" ) AddMaterial( "RedGlass", vec3d( 44, 2, 2 ), vec3d( 156, 10, 10 ), vec3d( 185, 159, 159 ), vec3d( 44, 2, 2 ), 30, 0.4 ) SetGeomMaterialName( pid, "RedGlass" ) # The new material joins the library and can then be applied by name. assert "RedGlass" in GetMaterialNames(), "AddMaterial did not add the material to the library" # Adding it again under the same name has to be rejected. The error queue is # reached through the error manager singleton in Python. err_mgr = ErrorMgrSingleton.getInstance() AddMaterial( "RedGlass", vec3d( 44, 2, 2 ), vec3d( 156, 10, 10 ), vec3d( 185, 159, 159 ), vec3d( 44, 2, 2 ), 30, 0.4 ) assert err_mgr.GetNumTotalErrors() > 0, "AddMaterial accepted a duplicate name" # That error was raised deliberately, so take it back off the queue. while err_mgr.GetNumTotalErrors() > 0 : err = err_mgr.PopLastError()
- Parameters:
[in] – name string Material name
[in] – ambient vec3d Ambient color RGB triple on scale [0, 255]
[in] – diffuse vec3d Diffuse color RGB triple on scale [0, 255]
[in] – specular vec3d Specular color RGB triple on scale [0, 255]
[in] – emissive vec3d Emissive color RGB triple on scale [0, 255]
[in] – shininess double Shininess exponent on scale [0, 127]
[in] – alpha double Transparency factor on scale [0, 1]
- openvsp.GetMaterialNames()[source]¶
Get the names of all visualization materials
mat_array = GetMaterialNames() assert len( mat_array ) > 0, "GetMaterialNames returned nothing" for i in range(int( len(mat_array) )): print( mat_array[i] )
- Return type:
std::vector< std::string,std::allocator< std::string > >
- Returns:
vector<string> Array of material names
- openvsp.GetNumLights()[source]¶
Get the number of lights in the model. The count is fixed: a model always has the same lights, each one either active or not.
#==== A model always has the same number of lights ====# assert GetNumLights() > 0, "GetNumLights did not count the lights" #==== Every one of them answers ====# for i in range( GetNumLights() ): assert len( FindLight( i ) ) > 0, "FindLight found nothing"
See also: FindLight :rtype: int :return: int Number of lights
- openvsp.FindLight(index)[source]¶
Get the ID of a light, so that its Parms can be reached the way any other container’s are. A light has an ActiveFlag, a position and ambient, diffuse and specular strengths, all in Parm group “Light_Parm”.
#==== Take the first light and put it somewhere of its own ====# light_id = FindLight( 0 ) assert len( light_id ) > 0, "FindLight found nothing" SetParmVal( FindParm( light_id, "ActiveFlag", "Light_Parm" ), 1.0 ) SetParmVal( FindParm( light_id, "X", "Light_Parm" ), 12.0 ) Update() moved = GetParmVal( light_id, "X", "Light_Parm" ) assert abs( moved - 12.0 ) < 1e-6, "the light did not take the position it was given" #==== Asking for one that is not there is refused. The error queue is reached through #==== the error manager singleton in Python, and is drained first so the count below is #==== about that call and not about anything before it. err_mgr = ErrorMgrSingleton.getInstance() while err_mgr.GetNumTotalErrors() > 0 : drained = err_mgr.PopLastError() FindLight( GetNumLights() ) assert err_mgr.GetNumTotalErrors() > 0, "FindLight answered for a light that does not exist" # That error was raised deliberately, so take it back off the queue. while err_mgr.GetNumTotalErrors() > 0 : err = err_mgr.PopLastError()
See also: GetNumLights :param [in]: index int Light index :rtype: string :return: string Light ID
- openvsp.SetBackground(r, g, b)[source]¶
Set the background color
SetBackground( 1.0, 1.0, 1.0 ) # Set background to bright white
- Parameters:
[in] – r double Red 8-bit unsigned integer (range: 0-255)
[in] – g double Green 8-bit unsigned integer (range: 0-255)
[in] – b double Blue 8-bit unsigned integer (range: 0-255)
- openvsp.SetAllViews(view)[source]¶
Set the view of all viewports
SetAllViews( CAM_CENTER )
- Parameters:
[in] – view int CAMERA_VIEW enum
- openvsp.SetView(viewport, view)[source]¶
Set the view of a particular viewports
SetView( 0, CAM_CENTER )
- Parameters:
[in] – viewport int Viewport to set view
[in] – view int CAMERA_VIEW enum
- openvsp.SetWindowLayout(r, c)[source]¶
Set the rows and columns of the window layout
SetWindowLayout( 2, 2 )
- Parameters:
[in] – r int Number of viewport rows
[in] – c int Number of viewport columns
- openvsp.SetGUIElementDisable(e, state)[source]¶
Set whether all instances of GUI device type are disabled
SetGUIElementDisable( GDEV_INPUT, True )
- Parameters:
[in] – e int GDEV enum for GUI device type
[in] – state bool True to disable GUI device type
- openvsp.SetGUIScreenDisable(s, state)[source]¶
Set whether screen is disabled
SetGUIScreenDisable( VSP_CFD_MESH_SCREEN, True )
- Parameters:
[in] – s int GUI_VSP_SCREEN enum for screen
[in] – state bool True to disable screen
- openvsp.SetGeomScreenDisable(s, state)[source]¶
Set whether geom screen is disabled
SetGeomScreenDisable( ALL_GEOM_SCREENS, True )
- Parameters:
[in] – s int GUI_GEOM_SCREEN enum for geom screen
[in] – state bool True to disable geom screen