OfflineRenderingUtils

Utility functions to work with FreeCAD files in console mode. More...

Classes

class  OfflineRenderingUtils.FreeCADGuiHandler
 

Functions

def OfflineRenderingUtils.buildGuiDocumentFromColors (document, colors, camera=None)
 
def OfflineRenderingUtils.buildGuiDocumentFromGuiData (document, guidata)
 
def OfflineRenderingUtils.buildScene (objects, colors=None)
 
def OfflineRenderingUtils.embedLight (scene, lightdir)
 
def OfflineRenderingUtils.extract (filename, inputpath, outputpath=None)
 
def OfflineRenderingUtils.getCamera (filepath)
 
def OfflineRenderingUtils.getCoinCamera (camerastring)
 
def OfflineRenderingUtils.getColors (filename, nodiffuse=False)
 
def OfflineRenderingUtils.getGuiData (filename)
 
def OfflineRenderingUtils.getStepData (objects, colors)
 
def OfflineRenderingUtils.getUnsigned (color)
 
def OfflineRenderingUtils.getViewProviderClass (obj)
 
def OfflineRenderingUtils.openiv (filename)
 
def OfflineRenderingUtils.render (outputfile, scene=None, camera=None, zoom=False, width=400, height=300, background=(1.0, 1.0, 1.0), lightdir=None)
 
def OfflineRenderingUtils.save (document, filename=None, guidata=None, colors=None, camera=None)
 
def OfflineRenderingUtils.saveDiffuseColor (colorlist)
 
def OfflineRenderingUtils.saveiv (scene, filename)
 
def OfflineRenderingUtils.viewer (scene=None, background=(1.0, 1.0, 1.0), lightdir=None)
 

Detailed Description

Utility functions to work with FreeCAD files in console mode.

Offline rendering utilities

Function Documentation

◆ buildGuiDocumentFromColors()

def OfflineRenderingUtils.buildGuiDocumentFromColors (   document,
  colors,
  camera = None 
)
buildGuiDocumentFromColors(document,colors,camera=None): Returns the path to a temporary GuiDocument.xml for the given document.
Colors is a color dictionary of objName:ShapeColorTuple or obj:DiffuseColorList. Camera, if given, is a string representing
a coin camera. You must delete the temporary file after using it.

References OfflineRenderingUtils.getUnsigned(), OfflineRenderingUtils.getViewProviderClass(), and OfflineRenderingUtils.saveDiffuseColor().

Referenced by OfflineRenderingUtils.save().

◆ buildGuiDocumentFromGuiData()

def OfflineRenderingUtils.buildGuiDocumentFromGuiData (   document,
  guidata 
)
buildGuiDocumentFromColors(document,guidata): Returns the path to a temporary GuiDocument.xml for the given document.

   GuiData is a dictionary, which can be obtained by the getGuiData() function, and has the form:

    { "objectName" :
        { "propertyName" :
            { "type"  : "App::PropertyString",
              "value" : "My Value"
            }
        }
    }
This function returns a list of (filepath,name) tuples, the first one named GuiDocument.xml and the next ones being color files

References OfflineRenderingUtils.getGuiData(), and OfflineRenderingUtils.getUnsigned().

Referenced by OfflineRenderingUtils.save().

◆ buildScene()

def OfflineRenderingUtils.buildScene (   objects,
  colors = None 
)
buildScene(objects,colors=None): builds a coin node from a given list of FreeCAD
objects. Optional colors argument can be a dictionary of objName:ShapeColorTuple
or obj:DiffuseColorList pairs.

◆ embedLight()

def OfflineRenderingUtils.embedLight (   scene,
  lightdir 
)
embedLight(scene,lightdir): embeds a given coin node
inside a shadow group with directional light with the
given direction (x,y,z) tuple. Returns the final coin node

Referenced by OfflineRenderingUtils.render(), and OfflineRenderingUtils.viewer().

◆ extract()

def OfflineRenderingUtils.extract (   filename,
  inputpath,
  outputpath = None 
)
extract(filename,inputpath,outputpath=None): extracts 'inputpath' which is a filename
stored in filename (a FreeCAD or zip file). If outputpath is given, the file is saved as outputpath and
nothing is returned. If not, the contents of the inputfile are returned and nothing is saved.

◆ getCamera()

def OfflineRenderingUtils.getCamera (   filepath)
getCamera(filepath): Returns a string representing a coin camera node from a given FreeCAD
file, or None if none was found inside

References OfflineRenderingUtils.getGuiData().

Referenced by Gui::GraphicsScene.addStateMachine(), importWebGL.export(), and Mod.Show.SceneDetails.Camera.Camera.scene_value().

◆ getCoinCamera()

def OfflineRenderingUtils.getCoinCamera (   camerastring)
getCoinCamera(camerastring): Returns a coin camera node from a string

Referenced by importWebGL.export(), and OfflineRenderingUtils.render().

◆ getColors()

def OfflineRenderingUtils.getColors (   filename,
  nodiffuse = False 
)
getColors(filename,nodiffuse): Extracts the colors saved in a FreeCAD file
Returns a dictionary containing ["objectName":colors] pairs.
colrs can be either a 3-element tuple representing an RGB color, if
the object has no per-face colors (DiffuseColor) defined, or a list
of tuples if per-face colors are available. In case of DiffuseColors,
tuples can have 4 values (RGBT) (T = transparency, inverse of alpha)
This is a reduced version of getGuiData(), which returns more information.
If nodiffuse = True, DiffuseColor info is discarded, only ShapeColor is read.

References OfflineRenderingUtils.getGuiData().

◆ getGuiData()

def OfflineRenderingUtils.getGuiData (   filename)
getGuiData(filename): Extract visual data from a saved FreeCAD file.
Returns a dictionary ["objectName:dict] where dict contains properties
keys  like ShapeColor, Transparency, DiffuseColor or Visibility. If found,
also contains a GuiCameraSettings key with an iv repr of a coin camera

Referenced by OfflineRenderingUtils.buildGuiDocumentFromGuiData(), OfflineRenderingUtils.getCamera(), OfflineRenderingUtils.getColors(), and OfflineRenderingUtils.save().

◆ getStepData()

def OfflineRenderingUtils.getStepData (   objects,
  colors 
)
getStepData(objects,colors): transforms the given list of objects and
colors dictionary into a list of tuples acceptable by the STEP exporter of
FreeCAD's Import module

◆ getUnsigned()

def OfflineRenderingUtils.getUnsigned (   color)
getUnsigned(color): returns an unsigned int from a (r,g,b) color tuple

Referenced by OfflineRenderingUtils.buildGuiDocumentFromColors(), and OfflineRenderingUtils.buildGuiDocumentFromGuiData().

◆ getViewProviderClass()

def OfflineRenderingUtils.getViewProviderClass (   obj)
getViewProviderClass(obj): tries to identify the associated view provider for a
   given python object. Returns a (modulename,classname) tuple if found, or None

Referenced by OfflineRenderingUtils.buildGuiDocumentFromColors().

◆ openiv()

def OfflineRenderingUtils.openiv (   filename)
openiv(filename): opens an .iv file and returns a coin node from it

◆ render()

def OfflineRenderingUtils.render (   outputfile,
  scene = None,
  camera = None,
  zoom = False,
  width = 400,
  height = 300,
  background = (1.0,1.0,1.0),
  lightdir = None 
)
render(outputfile,scene=None,camera=None,zoom=False,width=400,height=300,background=(1.0,1.0,1.0),lightdir=None):
Renders a PNG image of given width and height and background color from the given coin scene, using
the given coin camera (ortho or perspective). If zoom is True the camera will be resized to fit all
objects. The outputfile must be a file path to save a png image. Optionally a light direction as a (x,y,z)
tuple can be given. In this case, a directional light will be added and shadows will
be turned on. This might not work with some 3D drivers.

References OfflineRenderingUtils.embedLight(), and OfflineRenderingUtils.getCoinCamera().

Referenced by importWebGL.getHTMLTemplate(), package_list.PackageListItemDelegate.paint(), DrawingGui::SvgView.paintEvent(), TechDrawGui::QGVPage.paintEvent(), TechDrawGui::QGSPage.saveSvg(), and QSint::TaskGroup.transparentRender().

◆ save()

def OfflineRenderingUtils.save (   document,
  filename = None,
  guidata = None,
  colors = None,
  camera = None 
)
save(document,filename=None,guidata=None,colors=None,camera=None): Saves the current document. If no filename
   is given, the filename stored in the document (document.FileName) is used.

   You can provide a guidata dictionary, which can be obtained by the getGuiData() function, and has the form:

    { "objectName" :
        { "propertyName" :
            { "type"  : "App::PropertyString",
              "value" : "My Value"
            }
        }
    }

   The type of the "value" contents depends on the type (int, string, float,tuple...) see inside the FreeCADGuiHandler
   class to get an idea.

   If guidata is provided, colors and camera attributes are discarded.

   Alternatively, a color dictionary of objName:ShapeColorTuple or obj:DiffuseColorList pairs.can be provided,
   in that case the objects will keep their colors when opened in the FreeCAD GUI. If given, camera is a string
   representing a coin camera node.

References OfflineRenderingUtils.buildGuiDocumentFromColors(), OfflineRenderingUtils.buildGuiDocumentFromGuiData(), and OfflineRenderingUtils.getGuiData().

Referenced by Gui::MainWindow.closeAllDocuments(), SMESH_Mesh.Dump(), Gui::AutoSaver.saveDocument(), NETGENPlugin_Hypothesis.SaveTo(), NETGENPlugin_SimpleHypothesis_2D.SaveTo(), NETGENPlugin_SimpleHypothesis_3D.SaveTo(), SMESH_Algo.SaveTo(), StdMeshers_Adaptive1D.SaveTo(), StdMeshers_Arithmetic1D.SaveTo(), StdMeshers_AutomaticLength.SaveTo(), StdMeshers_CartesianParameters3D.SaveTo(), StdMeshers_Deflection1D.SaveTo(), StdMeshers_FixedPoints1D.SaveTo(), StdMeshers_Geometric1D.SaveTo(), StdMeshers_ImportSource1D.SaveTo(), StdMeshers_LayerDistribution.SaveTo(), StdMeshers_LengthFromEdges.SaveTo(), StdMeshers_LocalLength.SaveTo(), StdMeshers_MaxElementArea.SaveTo(), StdMeshers_MaxElementVolume.SaveTo(), StdMeshers_MaxLength.SaveTo(), StdMeshers_NotConformAllowed.SaveTo(), StdMeshers_NumberOfLayers.SaveTo(), StdMeshers_NumberOfSegments.SaveTo(), StdMeshers_ProjectionSource1D.SaveTo(), StdMeshers_ProjectionSource2D.SaveTo(), StdMeshers_ProjectionSource3D.SaveTo(), StdMeshers_Propagation.SaveTo(), StdMeshers_QuadrangleParams.SaveTo(), StdMeshers_QuadranglePreference.SaveTo(), StdMeshers_QuadraticMesh.SaveTo(), StdMeshers_Reversible1D.SaveTo(), StdMeshers_SegmentLengthAroundVertex.SaveTo(), StdMeshers_StartEndLength.SaveTo(), StdMeshers_TrianglePreference.SaveTo(), StdMeshers_ViscousLayers.SaveTo(), and SandboxGui::TaskPanelView.TaskPanelView().

◆ saveDiffuseColor()

def OfflineRenderingUtils.saveDiffuseColor (   colorlist)
saveDiffuseColor(colorlist): Saves the given list or tuple of
color tuples to a temp file, suitable to include in a DiffuseColor
property. Returns the path to the created temp file

Referenced by OfflineRenderingUtils.buildGuiDocumentFromColors().

◆ saveiv()

def OfflineRenderingUtils.saveiv (   scene,
  filename 
)
saveiv(scene,filename): saves an .iv file with the contents of the given coin node

◆ viewer()

def OfflineRenderingUtils.viewer (   scene = None,
  background = (1.0,1.0,1.0),
  lightdir = None 
)
viewer(scene=None,background=(1.0,1.0,1.0),lightdir=None): starts
a standalone coin viewer with the contents of the given scene. You can
give a background color, and optionally a light direction as a (x,y,z)
tuple. In this case, a directional light will be added and shadows will
be turned on. This might not work with some 3D drivers.

References OfflineRenderingUtils.embedLight().

Referenced by DrawingGui::TaskProjection.accept(), TechDrawGui::TaskProjection.accept(), SketcherGui::DrawSketchHandler.activate(), StdCmdAlignment.activated(), StdCmdEdit.activated(), StdCmdDrawStyle.activated(), StdCmdToggleNavigation.activated(), StdViewZoomIn.activated(), StdViewZoomOut.activated(), StdViewBoxZoom.activated(), StdBoxSelection.activated(), StdBoxElementSelection.activated(), StdCmdMeasureDistance.activated(), CmdViewMeasureClearAll.activated(), PartGui::FaceColors::Private.addFacesToSelection(), PartGui.addLinearDimensions(), Gui::AlignmentGroup.addToViewer(), Gui::Command.adjustCameraPosition(), SketcherGui::ViewProviderSketch.centerSelection(), Gui::Dialog::Clipping.Clipping(), TechDrawGui::Grabber3d.copyActiveViewToSvgFile(), MeshGui::MeshSelection.deselectTriangle(), SketcherGui::DrawSketchHandler.devicePixelRatio(), PartGui.eraseAllDimensions(), Gui::ViewProvider.eventCallback(), TechDrawGui::Grabber3d.execVectorizeAction(), MeshGui::MeshFaceAddition.finishEditing(), MeshGui::MeshFillHole.finishEditing(), TechDrawGui::DrawGuiUtil.get3DDirAndRot(), Gui::ViewProvider.getBoundingBox(), FemGui::ViewProviderFemPostFunction.getBoundingsOfView(), Gui::Document.getEditingViewOfViewProvider(), TechDrawGui::Grabber3d.getPaperScale(), MeshGui::ViewProviderFace.getPickedPoint(), Gui::ViewProviderGeometryObject.getPickedPoint(), Gui::ViewProviderGeometryObject.getPickedPoints(), Gui::ViewProvider.getPointOnRay(), PartDesignGui::ViewProviderDatum.getRelevantBoundBox(), SketcherGui::ViewProviderSketch.getScaleFactor(), PartGui.getViewer(), MeshGui::MeshSelection.getViewer(), Gui::View3DInventorPy.getViewer(), TechDrawGui::Grabber3d.getViewerScale(), PartGui.goDimensionAngularNoTask(), PartGui.goDimensionLinearNoTask(), Gui::AbstractMouseSelection.grabMouseModel(), StdCmdToggleNavigation.isActive(), StdCmdMeasureDistance.isActive(), PartGui::FaceColors::Private.isVisibleFace(), SketcherGui::ViewProviderSketch.mouseButtonPressed(), Gui::ViewProvider.mouseButtonPressed(), Gui::ViewProvider.mouseMove(), SketcherGui::ViewProviderSketch.mouseMove(), Gui::Flag.mouseMoveEvent(), SketcherGui::ViewProviderSketch.mouseWheelEvent(), Gui::ViewProvider.mouseWheelEvent(), NaviCube.NaviCube(), NaviCubeImplementation.NaviCubeImplementation(), MeshGui::MeshSelection.prepareFreehandSelection(), SketcherGui::ViewProviderSketch.purgeHandler(), Gui::AlignmentGroup.removeFromViewer(), Gui::Application.sCreateViewer(), MeshGui::MeshSelection.selectTriangle(), Gui::AbstractSplitViewPy.sequence_item(), SketcherGui::DrawSketchHandler.setCursor(), Gui::Dialog::DlgInspector.setDocument(), SketcherGui::ViewProviderSketch.setEditViewer(), Gui::ViewProviderPythonFeatureImp.setEditViewer(), Gui::ViewProviderDragger.setEditViewer(), Gui::ViewProviderLink.setEditViewer(), Gui::ViewProviderPythonFeatureT< ViewProviderT >.setEditViewer(), MeshGui::MeshSelection.setEnabledViewerSelection(), PartGui::BoxSelection.start(), MeshGui::MeshFaceAddition.startEditing(), MeshGui::MeshFillHole.startEditing(), MeshGui::MeshSelection.startInteractiveCallback(), MeshGui::MeshSelection.stopInteractiveCallback(), MeshGui::MeshSelection.stopSelection(), SketcherGui::DrawSketchHandler.suggestedConstraintsPixmaps(), SketcherGui::DrawSketchHandler.unsetCursor(), SketcherGui::ViewProviderSketch.unsetEditViewer(), Gui::ViewProviderPythonFeatureImp.unsetEditViewer(), Gui::ViewProviderDragger.unsetEditViewer(), Gui::ViewProviderLink.unsetEditViewer(), Gui::ViewProviderPythonFeatureT< ViewProviderT >.unsetEditViewer(), StdCmdDrawStyle.updateIcon(), PartDesignGui::ViewProviderBody.updateOriginDatumSize(), Gui::ViewProviderOriginGroupExtension.updateOriginSize(), PartGui::Location.~Location(), and MeshGui::MeshSelection.~MeshSelection().