KiCad PCB EDA Suite
Loading...
Searching...
No Matches
loadmodel.cpp File Reference
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <array>
#include <map>
#include <vector>
#include <atomic>
#include <wx/filename.h>
#include <wx/log.h>
#include <wx/stdpaths.h>
#include <wx/string.h>
#include <wx/utils.h>
#include <wx/wfstream.h>
#include <wx/zipstrm.h>
#include <plugins/3dapi/model_import.h>
#include "loadmodel.h"
#include "../model_import_internal.h"
#include <TDocStd_Document.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Shape.hxx>
#include <Quantity_Color.hxx>
#include <Quantity_ColorRGBA.hxx>
#include <XCAFApp_Application.hxx>
#include <IGESControl_Reader.hxx>
#include <IGESCAFControl_Reader.hxx>
#include <Interface_Static.hxx>
#include <STEPControl_Reader.hxx>
#include <STEPCAFControl_Reader.hxx>
#include <XCAFDoc_DocumentTool.hxx>
#include <XCAFDoc_ColorTool.hxx>
#include <XCAFDoc_ShapeTool.hxx>
#include <BRep_Tool.hxx>
#include <BRepMesh_IncrementalMesh.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS_Compound.hxx>
#include <TopExp_Explorer.hxx>
#include <Poly_Triangulation.hxx>
#include <Poly_PolygonOnTriangulation.hxx>
#include <Precision.hxx>
#include <NCollection_Sequence.hxx>
#include <TDF_Label.hxx>
#include <TDF_ChildIterator.hxx>
#include <TDF_Tool.hxx>
#include <TDataStd_Name.hxx>
#include <Standard_Version.hxx>
#include "plugins/3dapi/ifsg_all.h"

Go to the source code of this file.

Classes

struct  DATA
 

Macros

#define MASK_OCE   wxT( "PLUGIN_OCE" )
 
#define MASK_OCE_EXTRA   wxT( "PLUGIN_OCE_EXTRA" )
 
#define OCC_COLOR_SPACE   Quantity_TOC_RGB
 

Typedefs

typedef std::array< double, 4 > COLORKEY
 
typedef std::map< COLORKEY, IFSG_APPEARANCE > COLORMAP
 
typedef std::map< std::string, SGNODE * > FACEMAP
 
typedef std::map< std::string, std::vector< SGNODE * > > NODEMAP
 
typedef std::pair< std::string, std::vector< SGNODE * > > NODEITEM
 

Enumerations

enum  FormatType { FMT_NONE = 0 , FMT_STEP , FMT_STPZ , FMT_IGES }
 

Functions

bool processLabel (const TDF_Label &aLabel, DATA &aData, SGNODE *aParent, std::vector< SGNODE * > *aItems)
 
bool processFace (const TopoDS_Face &face, DATA &data, SGNODE *parent, std::vector< SGNODE * > *items, Quantity_ColorRGBA *color)
 
FormatType fileType (const char *aFileName)
 
void getTag (const TDF_Label &aLabel, std::string &aTag)
 Gets the absolute tag string for a given label in the form of ##:##:##:##.
 
static wxString getLabelName (const TDF_Label &aLabel)
 
std::string getShapeName (TopAbs_ShapeEnum aShape)
 Gets a string for a given TopAbs_ShapeEnum element.
 
static int colorFloatToDecimal (float aVal)
 
static std::ostream & operator<< (std::ostream &aOStream, const Quantity_ColorRGBA &aColor)
 
static void printLabel (TDF_Label aLabel, Handle(XCAFDoc_ShapeTool) aShapeTool, Handle(XCAFDoc_ColorTool) aColorTool, const char *aPreMsg=nullptr)
 Get a string for a given TopAbs_ShapeEnum element.
 
static void dumpLabels (TDF_Label aLabel, Handle(XCAFDoc_ShapeTool) aShapeTool, Handle(XCAFDoc_ColorTool) aColorTool, int aDepth=0)
 Dumps a label and the entire tree underneath it.
 
bool getColor (DATA &data, TDF_Label label, Quantity_ColorRGBA &color)
 
void addItems (SGNODE *parent, std::vector< SGNODE * > *lp)
 
bool readIGES (Handle(TDocStd_Document) &m_doc, const char *fname)
 
bool readSTEP (Handle(TDocStd_Document) &m_doc, const char *fname, double aLinearDeflection)
 
bool readSTEPZ (Handle(TDocStd_Document) &m_doc, const char *aFileName, const S3D::MODEL_IMPORT_OPTIONS &aOptions, MODEL_IMPORT_STATUS *aStatus)
 
SCENEGRAPH * LoadModel (char const *filename, const S3D::MODEL_IMPORT_OPTIONS *aOptions, MODEL_IMPORT_STATUS *aStatus)
 
bool processShell (const TopoDS_Shape &shape, DATA &data, SGNODE *parent, std::vector< SGNODE * > *items, Quantity_ColorRGBA *color)
 
bool processSolidOrShell (const TopoDS_Shape &shape, DATA &data, SGNODE *parent, std::vector< SGNODE * > *items)
 
SCENEGRAPH * LoadModel (const char *aFileName, const S3D::MODEL_IMPORT_OPTIONS *aOptions)
 

Macro Definition Documentation

◆ MASK_OCE

#define MASK_OCE   wxT( "PLUGIN_OCE" )

◆ MASK_OCE_EXTRA

#define MASK_OCE_EXTRA   wxT( "PLUGIN_OCE_EXTRA" )

Definition at line 89 of file loadmodel.cpp.

◆ OCC_COLOR_SPACE

#define OCC_COLOR_SPACE   Quantity_TOC_RGB

Definition at line 109 of file loadmodel.cpp.

Referenced by DATA::GetColor().

Typedef Documentation

◆ COLORKEY

typedef std::array<double, 4> COLORKEY

Definition at line 91 of file loadmodel.cpp.

◆ COLORMAP

typedef std::map<COLORKEY, IFSG_APPEARANCE> COLORMAP

Definition at line 92 of file loadmodel.cpp.

◆ FACEMAP

typedef std::map<std::string, SGNODE*> FACEMAP

Definition at line 93 of file loadmodel.cpp.

◆ NODEITEM

typedef std::pair<std::string, std::vector<SGNODE*> > NODEITEM

Definition at line 95 of file loadmodel.cpp.

◆ NODEMAP

typedef std::map<std::string, std::vector<SGNODE*> > NODEMAP

Definition at line 94 of file loadmodel.cpp.

Enumeration Type Documentation

◆ FormatType

enum FormatType
Enumerator
FMT_NONE 
FMT_STEP 
FMT_STPZ 
FMT_IGES 

Definition at line 295 of file loadmodel.cpp.

Function Documentation

◆ addItems()

void addItems ( SGNODE * parent,
std::vector< SGNODE * > * lp )

Definition at line 544 of file loadmodel.cpp.

References S3D::AddSGNodeChild(), S3D::AddSGNodeRef(), and S3D::GetSGNodeParent().

Referenced by processSolidOrShell().

◆ colorFloatToDecimal()

static int colorFloatToDecimal ( float aVal)
static

Definition at line 433 of file loadmodel.cpp.

Referenced by operator<<().

◆ dumpLabels()

static void dumpLabels ( TDF_Label aLabel,
Handle(XCAFDoc_ShapeTool) aShapeTool,
Handle(XCAFDoc_ColorTool) aColorTool,
int aDepth = 0 )
static

Dumps a label and the entire tree underneath it.

Parameters
aLabelLabel to convert
aShapeToolHandle to shape tool being used
aColorToolHandle to color tool being used
aDepthIndentation level to offset labels (used recursively by dumpLabels)

Definition at line 512 of file loadmodel.cpp.

References dumpLabels(), and printLabel().

Referenced by dumpLabels(), and LoadModel().

◆ fileType()

FormatType fileType ( const char * aFileName)

Definition at line 304 of file loadmodel.cpp.

References FMT_IGES, FMT_NONE, FMT_STEP, and FMT_STPZ.

Referenced by LoadModel().

◆ getColor()

bool getColor ( DATA & data,
TDF_Label label,
Quantity_ColorRGBA & color )

Definition at line 523 of file loadmodel.cpp.

References DATA::GetColor().

Referenced by processSolidOrShell().

◆ getLabelName()

static wxString getLabelName ( const TDF_Label & aLabel)
static

Definition at line 392 of file loadmodel.cpp.

References Handle(), and name.

Referenced by printLabel().

◆ getShapeName()

std::string getShapeName ( TopAbs_ShapeEnum aShape)

Gets a string for a given TopAbs_ShapeEnum element.

Parameters
aShapeenum value to convert

Definition at line 415 of file loadmodel.cpp.

Referenced by printLabel().

◆ getTag()

void getTag ( const TDF_Label & aLabel,
std::string & aTag )

Gets the absolute tag string for a given label in the form of ##:##:##:##.

Parameters
aLabelis the label to get the string for
aTagis the resulting tag string based by reference

Definition at line 368 of file loadmodel.cpp.

References MASK_OCE.

Referenced by processFace(), processLabel(), and processSolidOrShell().

◆ LoadModel() [1/2]

◆ LoadModel() [2/2]

SCENEGRAPH * LoadModel ( const char * aFileName,
const S3D::MODEL_IMPORT_OPTIONS * aOptions )

Definition at line 1338 of file loadmodel.cpp.

References MODEL_IMPORT_STATUS::diagnostic, LoadModel(), and MASK_OCE.

◆ operator<<()

static std::ostream & operator<< ( std::ostream & aOStream,
const Quantity_ColorRGBA & aColor )
inlinestatic

Definition at line 439 of file loadmodel.cpp.

References colorFloatToDecimal().

◆ printLabel()

static void printLabel ( TDF_Label aLabel,
Handle(XCAFDoc_ShapeTool) aShapeTool,
Handle(XCAFDoc_ColorTool) aColorTool,
const char * aPreMsg = nullptr )
static

Get a string for a given TopAbs_ShapeEnum element.

Parameters
aLabelLabel to convert.
aShapeToolHandle to shape tool being used.
aColorToolHandle to color tool being used.
aPreMsgAny prefixed message to insert (used for indentation in dump).

Definition at line 459 of file loadmodel.cpp.

References getLabelName(), getShapeName(), and MASK_OCE.

Referenced by dumpLabels().

◆ processFace()

◆ processLabel()

bool processLabel ( const TDF_Label & aLabel,
DATA & aData,
SGNODE * aParent,
std::vector< SGNODE * > * aItems )

◆ processShell()

bool processShell ( const TopoDS_Shape & shape,
DATA & data,
SGNODE * parent,
std::vector< SGNODE * > * items,
Quantity_ColorRGBA * color )

Definition at line 859 of file loadmodel.cpp.

References DATA::IsCanceled(), MASK_OCE, and processFace().

Referenced by processSolidOrShell().

◆ processSolidOrShell()

bool processSolidOrShell ( const TopoDS_Shape & shape,
DATA & data,
SGNODE * parent,
std::vector< SGNODE * > * items )

◆ readIGES()

bool readIGES ( Handle(TDocStd_Document) & m_doc,
const char * fname )

Definition at line 567 of file loadmodel.cpp.

Referenced by LoadModel().

◆ readSTEP()

bool readSTEP ( Handle(TDocStd_Document) & m_doc,
const char * fname,
double aLinearDeflection )

Definition at line 596 of file loadmodel.cpp.

References MASK_OCE.

Referenced by LoadModel(), and readSTEPZ().

◆ readSTEPZ()