KiCad PCB EDA Suite
oce.cpp File Reference
#include <wx/filename.h>
#include "plugins/3d/3d_plugin.h"
#include "plugins/3dapi/ifsg_all.h"
#include <string>
#include <vector>

Go to the source code of this file.

Classes

struct  FILE_DATA
 

Macros

#define PLUGIN_OCE_MAJOR   1
 
#define PLUGIN_OCE_MINOR   3
 
#define PLUGIN_OCE_PATCH   2
 
#define PLUGIN_OCE_REVNO   0
 

Functions

SCENEGRAPHLoadModel (char const *filename)
 
const char * GetKicadPluginName (void)
 Function GetKicadPluginName returns the name of the plugin instance; for example IDFv3. More...
 
void GetPluginVersion (unsigned char *Major, unsigned char *Minor, unsigned char *Patch, unsigned char *Revision)
 Function GetPluginVersion retrieves the version of the instantiated plugin for informational purposes. More...
 
int GetNExtensions (void)
 Function GetNExtensions. More...
 
char const * GetModelExtension (int aIndex)
 Function GetModelExtension. More...
 
int GetNFilters (void)
 Function GetNFilters. More...
 
char const * GetFileFilter (int aIndex)
 Function GetFileFilter. More...
 
bool CanRender (void)
 Function CanRender. More...
 
SCENEGRAPHLoad (char const *aFileName)
 reads a model file and creates a generic display structure More...
 

Variables

static struct FILE_DATA file_data
 

Macro Definition Documentation

◆ PLUGIN_OCE_MAJOR

#define PLUGIN_OCE_MAJOR   1

Definition at line 38 of file oce.cpp.

◆ PLUGIN_OCE_MINOR

#define PLUGIN_OCE_MINOR   3

Definition at line 39 of file oce.cpp.

◆ PLUGIN_OCE_PATCH

#define PLUGIN_OCE_PATCH   2

Definition at line 40 of file oce.cpp.

◆ PLUGIN_OCE_REVNO

#define PLUGIN_OCE_REVNO   0

Definition at line 41 of file oce.cpp.

Function Documentation

◆ CanRender()

bool CanRender ( void  )

Function CanRender.

Returns
true if the plugin can render a model, that is the Load() function is implemented

Definition at line 129 of file oce.cpp.

130 {
131  // this plugin supports rendering of IDF component outlines
132  return true;
133 }

◆ GetFileFilter()

char const* GetFileFilter ( int  aIndex)

Function GetFileFilter.

Returns
the file filter string for the given index

Definition at line 120 of file oce.cpp.

121 {
122  if( aIndex < 0 || aIndex >= int( file_data.filters.size() ) )
123  return nullptr;
124 
125  return file_data.filters[aIndex].c_str();
126 }
static struct FILE_DATA file_data
char const * filters[NFILS]

References file_data, and FILE_DATA::filters.

◆ GetKicadPluginName()

const char* GetKicadPluginName ( void  )

Function GetKicadPluginName returns the name of the plugin instance; for example IDFv3.

This string may be used to check for name conflicts or to display informational messages about loaded plugins. This method must be implemented in specific instantiations of a plugin class.

Returns
is the NULL-terminated UTF-8 string representing the plugin name

Definition at line 44 of file oce.cpp.

45 {
46  return "PLUGIN_3D_OCE";
47 }

◆ GetModelExtension()

char const* GetModelExtension ( int  aIndex)

Function GetModelExtension.

Parameters
aIndexis the extension to return; valid values are 0 to GetNExtensions() - 1.
Returns
the requested extension or a null string if aIndex was invalid.

Definition at line 105 of file oce.cpp.

106 {
107  if( aIndex < 0 || aIndex >= int( file_data.extensions.size() ) )
108  return nullptr;
109 
110  return file_data.extensions[aIndex].c_str();
111 }
static struct FILE_DATA file_data
char const * extensions[NEXTS]

References FILE_DATA::extensions, and file_data.

◆ GetNExtensions()

int GetNExtensions ( void  )

Function GetNExtensions.

Returns
the number of extensions supported by the plugin

Definition at line 99 of file oce.cpp.

100 {
101  return file_data.extensions.size();
102 }
static struct FILE_DATA file_data
char const * extensions[NEXTS]

References FILE_DATA::extensions, and file_data.

◆ GetNFilters()

int GetNFilters ( void  )

Function GetNFilters.

Returns
the number of file filters

Definition at line 114 of file oce.cpp.

115 {
116  return file_data.filters.size();
117 }
static struct FILE_DATA file_data
char const * filters[NFILS]

References file_data, and FILE_DATA::filters.

◆ GetPluginVersion()

void GetPluginVersion ( unsigned char *  Major,
unsigned char *  Minor,
unsigned char *  Patch,
unsigned char *  Revision 
)

Function GetPluginVersion retrieves the version of the instantiated plugin for informational purposes.

Do not confuse this with GetClassVersion which is used to determine API compatibility.

Parameters
Majorwill hold the Plugin Major version
Minorwill hold the Plugin Minor version
Patchwill hold the Plugin Patch level
Revisionwill hold the Plugin Revision

Definition at line 50 of file oce.cpp.

52 {
53  if( Major )
54  *Major = PLUGIN_OCE_MAJOR;
55 
56  if( Minor )
57  *Minor = PLUGIN_OCE_MINOR;
58 
59  if( Patch )
60  *Patch = PLUGIN_OCE_PATCH;
61 
62  if( Revision )
63  *Revision = PLUGIN_OCE_REVNO;
64 
65  return;
66 }
#define PLUGIN_OCE_MINOR
Definition: oce.cpp:39
#define PLUGIN_OCE_PATCH
Definition: oce.cpp:40
#define PLUGIN_OCE_REVNO
Definition: oce.cpp:41
#define PLUGIN_OCE_MAJOR
Definition: oce.cpp:38

References PLUGIN_OCE_MAJOR, PLUGIN_OCE_MINOR, PLUGIN_OCE_PATCH, and PLUGIN_OCE_REVNO.

◆ Load()

SCENEGRAPH* Load ( char const *  aFileName)

reads a model file and creates a generic display structure

Parameters
aFileNameis the full path of the model file
Returns
a SCENEGRAPH pointer to the display structure if the model was successfully loaded and NULL if there is no rendering support for the model or there were problems reading the model

Definition at line 136 of file oce.cpp.

137 {
138  if( nullptr == aFileName )
139  return nullptr;
140 
141  wxString fname = wxString::FromUTF8Unchecked( aFileName );
142 
143  if( !wxFileName::FileExists( fname ) )
144  return nullptr;
145 
146  return LoadModel( aFileName );
147 }
SCENEGRAPH * LoadModel(char const *filename)
Definition: loadmodel.cpp:660

References LoadModel().

◆ LoadModel()

SCENEGRAPH* LoadModel ( char const *  filename)

Definition at line 660 of file loadmodel.cpp.

661 {
662  DATA data;
663 
664  Handle(XCAFApp_Application) m_app = XCAFApp_Application::GetApplication();
665  m_app->NewDocument( "MDTV-XCAF", data.m_doc );
666  FormatType modelFmt = fileType( filename );
667 
668  switch( modelFmt )
669  {
670  case FMT_IGES:
671  data.renderBoth = true;
672 
673  if( !readIGES( data.m_doc, filename ) )
674  {
675  m_app->Close( data.m_doc );
676  return nullptr;
677  }
678 
679  break;
680 
681  case FMT_STEP:
682  if( !readSTEP( data.m_doc, filename ) )
683  {
684  m_app->Close( data.m_doc );
685  return nullptr;
686  }
687 
688  break;
689 
690  case FMT_STPZ:
691  if( !readSTEPZ( data.m_doc, filename ) )
692  {
693  m_app->Close( data.m_doc );
694  return nullptr;
695  }
696 
697  break;
698 
699 
700  default:
701  m_app->Close( data.m_doc );
702  return nullptr;
703  break;
704  }
705 
706  data.m_assy = XCAFDoc_DocumentTool::ShapeTool( data.m_doc->Main() );
707  data.m_color = XCAFDoc_DocumentTool::ColorTool( data.m_doc->Main() );
708 
709  // Check if the log mask is enabled otherwise the dump routine may be expensive before the wxLog call
710  if( wxLog::IsAllowedTraceMask( MASK_OCE ) )
711  {
712  dumpLabels( data.m_doc->Main(), data.m_assy, data.m_color );
713  }
714 
715  // retrieve all free shapes
716  TDF_LabelSequence frshapes;
717  data.m_assy->GetFreeShapes( frshapes );
718 
719  bool ret = false;
720 
721  // create the top level SG node
722  IFSG_TRANSFORM topNode( true );
723  data.scene = topNode.GetRawPtr();
724 
725  for( Standard_Integer i = 1; i <= frshapes.Length(); i++ )
726  {
727  const TDF_Label& label = frshapes.Value( i );
728 
729  if( data.m_color->IsVisible( label ) )
730  {
731  if( processLabel( label, data, data.scene, nullptr ) )
732  ret = true;
733  }
734  }
735 
736  if( !ret )
737  {
738  m_app->Close( data.m_doc );
739  return nullptr;
740  }
741 
742  SCENEGRAPH* scene = (SCENEGRAPH*)data.scene;
743 
744  // DEBUG: WRITE OUT VRML2 FILE TO CONFIRM STRUCTURE
745 #if ( defined( DEBUG_OCE ) && DEBUG_OCE > 3 )
746  if( data.scene )
747  {
748  wxFileName fn( wxString::FromUTF8Unchecked( filename ) );
749  wxString output;
750 
751  if( FMT_STEP == modelFmt )
752  output = wxT( "_step-" );
753  else
754  output = wxT( "_iges-" );
755 
756  output.append( fn.GetName() );
757  output.append( wxT( ".wrl" ) );
758  S3D::WriteVRML( output.ToUTF8(), true, data.scene, true, true );
759  }
760 #endif
761 
762  // set to NULL to prevent automatic destruction of the scene data
763  data.scene = nullptr;
764 
765  m_app->Close( data.m_doc );
766 
767  return scene;
768 }
bool readSTEPZ(Handle(TDocStd_Document)&m_doc, const char *aFileName)
Definition: loadmodel.cpp:590
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.
Definition: loadmodel.cpp:469
bool readSTEP(Handle(TDocStd_Document)&m_doc, const char *fname)
Definition: loadmodel.cpp:553
SGLIB_API bool WriteVRML(const char *filename, bool overwrite, SGNODE *aTopNode, bool reuse, bool renameNodes)
Function WriteVRML writes out the given node and its subnodes to a VRML2 file.
Definition: ifsg_api.cpp:77
FormatType fileType(const char *aFileName)
Definition: loadmodel.cpp:278
FormatType
Definition: loadmodel.cpp:269
bool readIGES(Handle(TDocStd_Document) &m_doc, const char *fname)
Definition: loadmodel.cpp:524
bool processLabel(const TDF_Label &aLabel, DATA &aData, SGNODE *aParent, std::vector< SGNODE * > *aItems)
Definition: loadmodel.cpp:904
#define MASK_OCE
Definition: loadmodel.cpp:87
SGNODE * scene
Definition: loadmodel.cpp:119
IFSG_TRANSFORM is the wrapper for the VRML compatible TRANSFORM block class SCENEGRAPH.
Define the basic data set required to represent a 3D model.
Definition: scenegraph.h:44
bool renderBoth
Definition: loadmodel.cpp:125

References dumpLabels(), fileType(), FMT_IGES, FMT_STEP, FMT_STPZ, IFSG_NODE::GetRawPtr(), MASK_OCE, processLabel(), readIGES(), readSTEP(), readSTEPZ(), DATA::renderBoth, DATA::scene, and S3D::WriteVRML().

Referenced by Load().

Variable Documentation

◆ file_data

struct FILE_DATA file_data
static