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   2
 
#define PLUGIN_OCE_PATCH   0
 
#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 39 of file oce.cpp.

◆ PLUGIN_OCE_MINOR

#define PLUGIN_OCE_MINOR   2

Definition at line 40 of file oce.cpp.

◆ PLUGIN_OCE_PATCH

#define PLUGIN_OCE_PATCH   0

Definition at line 41 of file oce.cpp.

◆ PLUGIN_OCE_REVNO

#define PLUGIN_OCE_REVNO   0

Definition at line 42 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 121 of file oce.cpp.

122 {
123  // this plugin supports rendering of IDF component outlines
124  return true;
125 }

◆ GetFileFilter()

char const* GetFileFilter ( int  aIndex)

Function GetFileFilter.

Returns
the file filter string for the given index

Definition at line 112 of file oce.cpp.

113 {
114  if( aIndex < 0 || aIndex >= int( file_data.filters.size() ) )
115  return NULL;
116 
117  return file_data.filters[aIndex].c_str();
118 }
static struct FILE_DATA file_data
#define NULL
char const * filters[NFILS]

References file_data, FILE_DATA::filters, and NULL.

◆ 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 45 of file oce.cpp.

46 {
47  return "PLUGIN_3D_OCE";
48 }

◆ 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 97 of file oce.cpp.

98 {
99  if( aIndex < 0 || aIndex >= int( file_data.extensions.size() ) )
100  return NULL;
101 
102  return file_data.extensions[aIndex].c_str();
103 }
static struct FILE_DATA file_data
char const * extensions[NEXTS]
#define NULL

References FILE_DATA::extensions, file_data, and NULL.

◆ GetNExtensions()

int GetNExtensions ( void  )

Function GetNExtensions.

Returns
the number of extensions supported by the plugin

Definition at line 91 of file oce.cpp.

92 {
93  return file_data.extensions.size();
94 }
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 106 of file oce.cpp.

107 {
108  return file_data.filters.size();
109 }
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 51 of file oce.cpp.

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

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 128 of file oce.cpp.

129 {
130  if( NULL == aFileName )
131  return NULL;
132 
133  wxString fname = wxString::FromUTF8Unchecked( aFileName );
134 
135  if( !wxFileName::FileExists( fname ) )
136  return NULL;
137 
138  return LoadModel( aFileName );
139 }
SCENEGRAPH * LoadModel(char const *filename)
Definition: loadmodel.cpp:532
#define NULL

References LoadModel(), and NULL.

◆ LoadModel()

SCENEGRAPH* LoadModel ( char const *  filename)

Definition at line 532 of file loadmodel.cpp.

533 {
534  DATA data;
535 
536  Handle(XCAFApp_Application) m_app = XCAFApp_Application::GetApplication();
537  m_app->NewDocument( "MDTV-XCAF", data.m_doc );
538  FormatType modelFmt = fileType( filename );
539 
540  switch( modelFmt )
541  {
542  case FMT_IGES:
543  data.renderBoth = true;
544 
545  if( !readIGES( data.m_doc, filename ) )
546  return NULL;
547  break;
548 
549  case FMT_STEP:
550  if( !readSTEP( data.m_doc, filename ) )
551  return NULL;
552  break;
553 
554  case FMT_STPZ:
555  if( !readSTEPZ( data.m_doc, filename ) )
556  return NULL;
557  break;
558 
559 
560  default:
561  return NULL;
562  break;
563  }
564 
565  data.m_assy = XCAFDoc_DocumentTool::ShapeTool( data.m_doc->Main() );
566  data.m_color = XCAFDoc_DocumentTool::ColorTool( data.m_doc->Main() );
567 
568  // retrieve all free shapes
569  TDF_LabelSequence frshapes;
570  data.m_assy->GetFreeShapes( frshapes );
571 
572  int nshapes = frshapes.Length();
573  int id = 1;
574  bool ret = false;
575 
576  // create the top level SG node
577  IFSG_TRANSFORM topNode( true );
578  data.scene = topNode.GetRawPtr();
579 
580  while( id <= nshapes )
581  {
582  TopoDS_Shape shape = data.m_assy->GetShape( frshapes.Value(id) );
583 
584  if ( !shape.IsNull() && processNode( shape, data, data.scene, NULL ) )
585  ret = true;
586 
587  ++id;
588  };
589 
590  if( !ret )
591  return NULL;
592 
593  SCENEGRAPH* scene = (SCENEGRAPH*)data.scene;
594 
595  // DEBUG: WRITE OUT VRML2 FILE TO CONFIRM STRUCTURE
596  #if ( defined( DEBUG_OCE ) && DEBUG_OCE > 3 )
597  if( data.scene )
598  {
599  wxFileName fn( wxString::FromUTF8Unchecked( filename ) );
600  wxString output;
601 
602  if( FMT_STEP == modelFmt )
603  output = wxT( "_step-" );
604  else
605  output = wxT( "_iges-" );
606 
607  output.append( fn.GetName() );
608  output.append( wxT(".wrl") );
609  S3D::WriteVRML( output.ToUTF8(), true, data.scene, true, true );
610  }
611  #endif
612 
613  // set to NULL to prevent automatic destruction of the scene data
614  data.scene = NULL;
615 
616  return scene;
617 }
bool readSTEPZ(Handle(TDocStd_Document)&m_doc, const char *aFileName)
Definition: loadmodel.cpp:462
bool readSTEP(Handle(TDocStd_Document)&m_doc, const char *fname)
Definition: loadmodel.cpp:427
bool processNode(const TopoDS_Shape &shape, DATA &data, SGNODE *parent, std::vector< SGNODE * > *items)
Definition: loadmodel.cpp:816
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:76
#define NULL
bool readIGES(Handle(TDocStd_Document)&m_doc, const char *fname)
Definition: loadmodel.cpp:398
FormatType fileType(const char *aFileName)
Definition: loadmodel.cpp:273
FormatType
Definition: loadmodel.cpp:264
SGNODE * scene
Definition: loadmodel.cpp:112
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:118
bool GetShape(const std::string &id, std::vector< SGNODE * > *&listPtr)
Definition: loadmodel.cpp:202

References fileType(), FMT_IGES, FMT_STEP, FMT_STPZ, IFSG_NODE::GetRawPtr(), DATA::GetShape(), NULL, processNode(), readIGES(), readSTEP(), readSTEPZ(), DATA::renderBoth, DATA::scene, and S3D::WriteVRML().

Referenced by Load().

Variable Documentation

◆ file_data

struct FILE_DATA file_data
static