KiCad PCB EDA Suite
loadmodel.cpp File Reference
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <map>
#include <vector>
#include <wx/string.h>
#include <wx/wfstream.h>
#include <TDocStd_Document.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Shape.hxx>
#include <Quantity_Color.hxx>
#include <XCAFApp_Application.hxx>
#include <AIS_Shape.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 <TDF_LabelSequence.hxx>
#include <TDF_ChildIterator.hxx>
#include "plugins/3dapi/ifsg_all.h"

Go to the source code of this file.

Classes

struct  DATA
 

Macros

#define MASK_OCE   "PLUGIN_OCE"
 
#define USER_PREC   (0.14)
 
#define USER_ANGLE   (0.52359878)
 

Typedefs

typedef std::map< Standard_Real, SGNODE * > 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 = 1, FMT_IGES = 2 }
 

Functions

bool processNode (const TopoDS_Shape &shape, DATA &data, SGNODE *parent, std::vector< SGNODE * > *items)
 
bool processComp (const TopoDS_Shape &shape, DATA &data, SGNODE *parent, std::vector< SGNODE * > *items)
 
bool processFace (const TopoDS_Face &face, DATA &data, SGNODE *parent, std::vector< SGNODE * > *items, Quantity_Color *color)
 
FormatType fileType (const char *aFileName)
 
void getTag (TDF_Label &label, std::string &aTag)
 
bool getColor (DATA &data, TDF_Label label, Quantity_Color &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)
 
SCENEGRAPHLoadModel (char const *filename)
 
bool processShell (const TopoDS_Shape &shape, DATA &data, SGNODE *parent, std::vector< SGNODE * > *items, Quantity_Color *color)
 
bool processSolid (const TopoDS_Shape &shape, DATA &data, SGNODE *parent, std::vector< SGNODE * > *items)
 

Macro Definition Documentation

◆ MASK_OCE

#define MASK_OCE   "PLUGIN_OCE"

Definition at line 77 of file loadmodel.cpp.

◆ USER_ANGLE

#define USER_ANGLE   (0.52359878)

Definition at line 86 of file loadmodel.cpp.

◆ USER_PREC

#define USER_PREC   (0.14)

Definition at line 80 of file loadmodel.cpp.

Typedef Documentation

◆ COLORMAP

typedef std::map< Standard_Real, SGNODE* > COLORMAP

Definition at line 88 of file loadmodel.cpp.

◆ FACEMAP

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

Definition at line 89 of file loadmodel.cpp.

◆ NODEITEM

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

Definition at line 91 of file loadmodel.cpp.

◆ NODEMAP

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

Definition at line 90 of file loadmodel.cpp.

Enumeration Type Documentation

◆ FormatType

enum FormatType
Enumerator
FMT_NONE 
FMT_STEP 
FMT_IGES 

Definition at line 261 of file loadmodel.cpp.

262 {
263  FMT_NONE = 0,
264  FMT_STEP = 1,
265  FMT_IGES = 2
266 };

Function Documentation

◆ addItems()

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

Definition at line 365 of file loadmodel.cpp.

366 {
367  if( NULL == lp )
368  return;
369 
370  std::vector< SGNODE* >::iterator sL = lp->begin();
371  std::vector< SGNODE* >::iterator eL = lp->end();
372  SGNODE* item;
373 
374  while( sL != eL )
375  {
376  item = *sL;
377 
378  if( NULL == S3D::GetSGNodeParent( item ) )
379  S3D::AddSGNodeChild( parent, item );
380  else
381  S3D::AddSGNodeRef( parent, item );
382 
383  ++sL;
384  }
385 
386  return;
387 }
SGLIB_API SGNODE * GetSGNodeParent(SGNODE *aNode)
Definition: ifsg_api.cpp:636
SGNODE represents the base class of all Scene Graph nodes.
Definition: sg_node.h:76
SGLIB_API bool AddSGNodeRef(SGNODE *aParent, SGNODE *aChild)
Definition: ifsg_api.cpp:645
#define NULL
SGLIB_API bool AddSGNodeChild(SGNODE *aParent, SGNODE *aChild)
Definition: ifsg_api.cpp:654

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

Referenced by processSolid().

◆ fileType()

FormatType fileType ( const char *  aFileName)

Definition at line 269 of file loadmodel.cpp.

270 {
271  wxString fname( wxString::FromUTF8Unchecked( aFileName ) );
272  wxFileInputStream ifile( fname );
273 
274  if( !ifile.IsOk() )
275  return FMT_NONE;
276 
277  char iline[82];
278  memset( iline, 0, 82 );
279  ifile.Read( iline, 82 );
280  iline[81] = 0; // ensure NULL termination when string is too long
281 
282  // check for STEP in Part 21 format
283  // (this can give false positives since Part 21 is not exclusively STEP)
284  if( !strncmp( iline, "ISO-10303-21;", 13 ) )
285  return FMT_STEP;
286 
287  std::string fstr = iline;
288 
289  // check for STEP in XML format
290  // (this can give both false positive and false negatives)
291  if( fstr.find( "urn:oid:1.0.10303." ) != std::string::npos )
292  return FMT_STEP;
293 
294  // Note: this is a very simple test which can yield false positives; the only
295  // sure method for determining if a file *not* an IGES model is to attempt
296  // to load it.
297  if( iline[72] == 'S' && ( iline[80] == 0 || iline[80] == 13 || iline[80] == 10 ) )
298  return FMT_IGES;
299 
300  return FMT_NONE;
301 }

References FMT_IGES, FMT_NONE, and FMT_STEP.

Referenced by PANEL_FP_LIB_TABLE::browseLibrariesHandler(), GERBVIEW_FRAME::Files_io(), GRAPHICS_IMPORT_MGR::GetPluginByExt(), FOOTPRINT_EDIT_FRAME::Import_Module(), LoadModel(), PANEL_FP_LIB_TABLE::PANEL_FP_LIB_TABLE(), and LIB_EDIT_FRAME::saveLibrary().

◆ getColor()

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

Definition at line 344 of file loadmodel.cpp.

345 {
346  while( true )
347  {
348  if( data.m_color->GetColor( label, XCAFDoc_ColorGen, color ) )
349  return true;
350  else if( data.m_color->GetColor( label, XCAFDoc_ColorSurf, color ) )
351  return true;
352  else if( data.m_color->GetColor( label, XCAFDoc_ColorCurv, color ) )
353  return true;
354 
355  label = label.Father();
356 
357  if( label.IsNull() )
358  break;
359  };
360 
361  return false;
362 }
SGNODE * GetColor(Quantity_Color *colorObj)
Definition: loadmodel.cpp:225
int color
Definition: DXF_plotter.cpp:61

References color, and DATA::GetColor().

Referenced by processSolid().

◆ getTag()

void getTag ( TDF_Label &  label,
std::string &  aTag 
)

Definition at line 304 of file loadmodel.cpp.

305 {
306  if( label.IsNull() )
307  return;
308 
309  std::string rtag; // tag in reverse
310  aTag.clear();
311  int id = label.Tag();
312  std::ostringstream ostr;
313  ostr << id;
314  rtag = ostr.str();
315  ostr.str( "" );
316  ostr.clear();
317 
318  TDF_Label nlab = label.Father();
319 
320  while( !nlab.IsNull() )
321  {
322  rtag.append( 1, ':' );
323  id = nlab.Tag();
324  ostr << id;
325  rtag.append( ostr.str() );
326  ostr.str( "" );
327  ostr.clear();
328  nlab = nlab.Father();
329  };
330 
331  std::string::reverse_iterator bI = rtag.rbegin();
332  std::string::reverse_iterator eI = rtag.rend();
333 
334  while( bI != eI )
335  {
336  aTag.append( 1, *bI );
337  ++bI;
338  }
339 
340  return;
341 }

Referenced by processFace(), and processSolid().

◆ LoadModel()

SCENEGRAPH* LoadModel ( char const *  filename)

Definition at line 454 of file loadmodel.cpp.

455 {
456  DATA data;
457 
458  Handle(XCAFApp_Application) m_app = XCAFApp_Application::GetApplication();
459  m_app->NewDocument( "MDTV-XCAF", data.m_doc );
460  FormatType modelFmt = fileType( filename );
461 
462  switch( modelFmt )
463  {
464  case FMT_IGES:
465  data.renderBoth = true;
466 
467  if( !readIGES( data.m_doc, filename ) )
468  return NULL;
469  break;
470 
471  case FMT_STEP:
472  if( !readSTEP( data.m_doc, filename ) )
473  return NULL;
474  break;
475 
476  default:
477  return NULL;
478  break;
479  }
480 
481  data.m_assy = XCAFDoc_DocumentTool::ShapeTool( data.m_doc->Main() );
482  data.m_color = XCAFDoc_DocumentTool::ColorTool( data.m_doc->Main() );
483 
484  // retrieve all free shapes
485  TDF_LabelSequence frshapes;
486  data.m_assy->GetFreeShapes( frshapes );
487 
488  int nshapes = frshapes.Length();
489  int id = 1;
490  bool ret = false;
491 
492  // create the top level SG node
493  IFSG_TRANSFORM topNode( true );
494  data.scene = topNode.GetRawPtr();
495 
496  while( id <= nshapes )
497  {
498  TopoDS_Shape shape = data.m_assy->GetShape( frshapes.Value(id) );
499 
500  if ( !shape.IsNull() && processNode( shape, data, data.scene, NULL ) )
501  ret = true;
502 
503  ++id;
504  };
505 
506  if( !ret )
507  return NULL;
508 
509  SCENEGRAPH* scene = (SCENEGRAPH*)data.scene;
510 
511  // DEBUG: WRITE OUT VRML2 FILE TO CONFIRM STRUCTURE
512  #if ( defined( DEBUG_OCE ) && DEBUG_OCE > 3 )
513  if( data.scene )
514  {
515  wxFileName fn( wxString::FromUTF8Unchecked( filename ) );
516  wxString output;
517 
518  if( FMT_STEP == modelFmt )
519  output = wxT( "_step-" );
520  else
521  output = wxT( "_iges-" );
522 
523  output.append( fn.GetName() );
524  output.append( wxT(".wrl") );
525  S3D::WriteVRML( output.ToUTF8(), true, data.scene, true, true );
526  }
527  #endif
528 
529  // set to NULL to prevent automatic destruction of the scene data
530  data.scene = NULL;
531 
532  return scene;
533 }
bool readSTEP(Handle(TDocStd_Document)&m_doc, const char *fname)
Definition: loadmodel.cpp:419
bool processNode(const TopoDS_Shape &shape, DATA &data, SGNODE *parent, std::vector< SGNODE * > *items)
Definition: loadmodel.cpp:695
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:81
#define NULL
bool readIGES(Handle(TDocStd_Document)&m_doc, const char *fname)
Definition: loadmodel.cpp:390
FormatType fileType(const char *aFileName)
Definition: loadmodel.cpp:269
FormatType
Definition: loadmodel.cpp:261
SGNODE * scene
Definition: loadmodel.cpp:109
IFSG_TRANSFORM is the wrapper for the VRML compatible TRANSFORM block class SCENEGRAPH.
bool renderBoth
Definition: loadmodel.cpp:115
bool GetShape(const std::string &id, std::vector< SGNODE * > *&listPtr)
Definition: loadmodel.cpp:199

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

Referenced by Load().

◆ processComp()

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

Definition at line 631 of file loadmodel.cpp.

633 {
634  TopoDS_Iterator it;
635  IFSG_TRANSFORM childNode( parent );
636  SGNODE* pptr = childNode.GetRawPtr();
637  const TopLoc_Location& loc = shape.Location();
638  bool ret = false;
639 
640  if( !loc.IsIdentity() )
641  {
642  gp_Trsf T = loc.Transformation();
643  gp_XYZ coord = T.TranslationPart();
644  childNode.SetTranslation( SGPOINT( coord.X(), coord.Y(), coord.Z() ) );
645  gp_XYZ axis;
646  Standard_Real angle;
647 
648  if( T.GetRotation( axis, angle ) )
649  childNode.SetRotation( SGVECTOR( axis.X(), axis.Y(), axis.Z() ), angle );
650  }
651 
652  for( it.Initialize( shape, false, false ); it.More(); it.Next() )
653  {
654  const TopoDS_Shape& subShape = it.Value();
655  TopAbs_ShapeEnum stype = subShape.ShapeType();
656  data.hasSolid = false;
657 
658  switch( stype )
659  {
660  case TopAbs_COMPOUND:
661  case TopAbs_COMPSOLID:
662  if( processComp( subShape, data, pptr, items ) )
663  ret = true;
664  break;
665 
666  case TopAbs_SOLID:
667  if( processSolid( subShape, data, pptr, items ) )
668  ret = true;
669  break;
670 
671  case TopAbs_SHELL:
672  if( processShell( subShape, data, pptr, items, NULL ) )
673  ret = true;
674  break;
675 
676  case TopAbs_FACE:
677  if( processFace( TopoDS::Face( subShape ), data, pptr, items, NULL ) )
678  ret = true;
679  break;
680 
681  default:
682  break;
683  }
684  }
685 
686  if( !ret )
687  childNode.Destroy();
688  else if( NULL != items )
689  items->push_back( pptr );
690 
691  return ret;
692 }
bool processSolid(const TopoDS_Shape &shape, DATA &data, SGNODE *parent, std::vector< SGNODE * > *items)
Definition: loadmodel.cpp:554
T
enum T contains all this lexer's tokens.
SGNODE represents the base class of all Scene Graph nodes.
Definition: sg_node.h:76
#define NULL
bool processFace(const TopoDS_Face &face, DATA &data, SGNODE *parent, std::vector< SGNODE * > *items, Quantity_Color *color)
Definition: loadmodel.cpp:733
bool hasSolid
Definition: loadmodel.cpp:116
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
IFSG_TRANSFORM is the wrapper for the VRML compatible TRANSFORM block class SCENEGRAPH.
bool processComp(const TopoDS_Shape &shape, DATA &data, SGNODE *parent, std::vector< SGNODE * > *items)
Definition: loadmodel.cpp:631
bool processShell(const TopoDS_Shape &shape, DATA &data, SGNODE *parent, std::vector< SGNODE * > *items, Quantity_Color *color)
Definition: loadmodel.cpp:536

References PNS::angle(), IFSG_NODE::Destroy(), IFSG_NODE::GetRawPtr(), DATA::hasSolid, NULL, processFace(), processShell(), processSolid(), IFSG_TRANSFORM::SetRotation(), and IFSG_TRANSFORM::SetTranslation().

Referenced by processNode().

◆ processFace()

bool processFace ( const TopoDS_Face &  face,
DATA data,
SGNODE parent,
std::vector< SGNODE * > *  items,
Quantity_Color *  color 
)

Definition at line 733 of file loadmodel.cpp.

735 {
736  if( Standard_True == face.IsNull() )
737  return false;
738 
739  bool reverse = ( face.Orientation() == TopAbs_REVERSED );
740  SGNODE* ashape = NULL;
741  std::string partID;
742  TDF_Label label;
743 
744  bool useBothSides = false;
745 
746  // for IGES renderBoth = TRUE; for STEP if a shell or face is not a descendant
747  // of a SOLID then hasSolid = false and we must render both sides
748  if( data.renderBoth || !data.hasSolid )
749  useBothSides = true;
750 
751  if( data.m_assy->FindShape( face, label, Standard_False ) )
752  getTag( label, partID );
753 
754  if( !partID.empty() )
755  ashape = data.GetFace( partID );
756 
757  if( ashape )
758  {
759  if( NULL == S3D::GetSGNodeParent( ashape ) )
760  S3D::AddSGNodeChild( parent, ashape );
761  else
762  S3D::AddSGNodeRef( parent, ashape );
763 
764  if( NULL != items )
765  items->push_back( ashape );
766 
767  if( useBothSides )
768  {
769  std::string id2 = partID;
770  id2.append( "b" );
771  SGNODE* shapeB = data.GetFace( id2 );
772 
773  if( NULL == S3D::GetSGNodeParent( shapeB ) )
774  S3D::AddSGNodeChild( parent, shapeB );
775  else
776  S3D::AddSGNodeRef( parent, shapeB );
777 
778  if( NULL != items )
779  items->push_back( shapeB );
780  }
781 
782  return true;
783  }
784 
785  TopLoc_Location loc;
786  Standard_Boolean isTessellate (Standard_False);
787  Handle(Poly_Triangulation) triangulation = BRep_Tool::Triangulation( face, loc );
788 
789  if( triangulation.IsNull() || triangulation->Deflection() > USER_PREC + Precision::Confusion() )
790  isTessellate = Standard_True;
791 
792  if (isTessellate)
793  {
794  BRepMesh_IncrementalMesh IM(face, USER_PREC, Standard_False, USER_ANGLE );
795  triangulation = BRep_Tool::Triangulation( face, loc );
796  }
797 
798  if( triangulation.IsNull() == Standard_True )
799  return false;
800 
801  Quantity_Color lcolor;
802 
803  // check for a face color; this has precedence over SOLID colors
804  do
805  {
806  TDF_Label L;
807 
808  if( data.m_color->ShapeTool()->Search( face, L ) )
809  {
810  if( data.m_color->GetColor( L, XCAFDoc_ColorGen, lcolor )
811  || data.m_color->GetColor( L, XCAFDoc_ColorCurv, lcolor )
812  || data.m_color->GetColor( L, XCAFDoc_ColorSurf, lcolor ) )
813  color = &lcolor;
814  }
815  } while( 0 );
816 
817  SGNODE* ocolor = data.GetColor( color );
818 
819  // create a SHAPE and attach the color and data,
820  // then attach the shape to the parent and return TRUE
821  IFSG_SHAPE vshape( true );
822  IFSG_FACESET vface( vshape );
823  IFSG_COORDS vcoords( vface );
824  IFSG_COORDINDEX coordIdx( vface );
825 
826  if( NULL == S3D::GetSGNodeParent( ocolor ) )
827  S3D::AddSGNodeChild( vshape.GetRawPtr(), ocolor );
828  else
829  S3D::AddSGNodeRef( vshape.GetRawPtr(), ocolor );
830 
831  const TColgp_Array1OfPnt& arrPolyNodes = triangulation->Nodes();
832  const Poly_Array1OfTriangle& arrTriangles = triangulation->Triangles();
833 
834  std::vector< SGPOINT > vertices;
835  std::vector< int > indices;
836  std::vector< int > indices2;
837  gp_Trsf tx;
838 
839  for(int i = 1; i <= triangulation->NbNodes(); i++)
840  {
841  gp_XYZ v( arrPolyNodes(i).Coord() );
842  vertices.emplace_back( v.X(), v.Y(), v.Z() );
843  }
844 
845  for(int i = 1; i <= triangulation->NbTriangles(); i++)
846  {
847  int a, b, c;
848  arrTriangles( i ).Get( a, b, c );
849  a--;
850 
851  if( reverse )
852  {
853  int tmp = b - 1;
854  b = c - 1;
855  c = tmp;
856  } else {
857  b--;
858  c--;
859  }
860 
861  indices.push_back( a );
862  indices.push_back( b );
863  indices.push_back( c );
864 
865  if( useBothSides )
866  {
867  indices2.push_back( b );
868  indices2.push_back( a );
869  indices2.push_back( c );
870  }
871  }
872 
873  vcoords.SetCoordsList( vertices.size(), &vertices[0] );
874  coordIdx.SetIndices( indices.size(), &indices[0] );
875  vface.CalcNormals( NULL );
876  vshape.SetParent( parent );
877 
878  if( !partID.empty() )
879  data.faces.insert( std::pair< std::string,
880  SGNODE* >( partID, vshape.GetRawPtr() ) );
881 
882  // The outer surface of an IGES model is indeterminate so
883  // we must render both sides of a surface.
884  if( useBothSides )
885  {
886  std::string id2 = partID;
887  id2.append( "b" );
888  IFSG_SHAPE vshape2( true );
889  IFSG_FACESET vface2( vshape2 );
890  IFSG_COORDS vcoords2( vface2 );
891  IFSG_COORDINDEX coordIdx2( vface2 );
892  S3D::AddSGNodeRef( vshape2.GetRawPtr(), ocolor );
893 
894  vcoords2.SetCoordsList( vertices.size(), &vertices[0] );
895  coordIdx2.SetIndices( indices2.size(), &indices2[0] );
896  vface2.CalcNormals( NULL );
897  vshape2.SetParent( parent );
898 
899  if( !partID.empty() )
900  data.faces.insert( std::pair< std::string,
901  SGNODE* >( id2, vshape2.GetRawPtr() ) );
902  }
903 
904  return true;
905 }
SGNODE * GetColor(Quantity_Color *colorObj)
Definition: loadmodel.cpp:225
IFSG_COORDS is the wrapper for SGCOORDS.
Definition: ifsg_coords.h:40
IFSG_COORDINDEX is the wrapper for SGCOORDINDEX.
SGNODE * GetFace(const std::string &id)
Definition: loadmodel.cpp:213
FACEMAP faces
Definition: loadmodel.cpp:114
int color
Definition: DXF_plotter.cpp:61
SGLIB_API SGNODE * GetSGNodeParent(SGNODE *aNode)
Definition: ifsg_api.cpp:636
SGNODE represents the base class of all Scene Graph nodes.
Definition: sg_node.h:76
SGLIB_API bool AddSGNodeRef(SGNODE *aParent, SGNODE *aChild)
Definition: ifsg_api.cpp:645
#define NULL
void getTag(TDF_Label &label, std::string &aTag)
Definition: loadmodel.cpp:304
#define USER_ANGLE
Definition: loadmodel.cpp:86
SGLIB_API bool AddSGNodeChild(SGNODE *aParent, SGNODE *aChild)
Definition: ifsg_api.cpp:654
#define USER_PREC
Definition: loadmodel.cpp:80
bool hasSolid
Definition: loadmodel.cpp:116
IFSG_FACESET is the wrapper for the SGFACESET class.
Definition: ifsg_faceset.h:40
bool renderBoth
Definition: loadmodel.cpp:115
IFSG_SHAPE is the wrapper for the SGSHAPE class.
Definition: ifsg_shape.h:40

References S3D::AddSGNodeChild(), S3D::AddSGNodeRef(), IFSG_FACESET::CalcNormals(), color, DATA::faces, DATA::GetColor(), DATA::GetFace(), IFSG_NODE::GetRawPtr(), S3D::GetSGNodeParent(), getTag(), DATA::hasSolid, NULL, DATA::renderBoth, IFSG_COORDS::SetCoordsList(), IFSG_INDEX::SetIndices(), IFSG_NODE::SetParent(), USER_ANGLE, and USER_PREC.

Referenced by processComp(), processNode(), and processShell().

◆ processNode()

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

Definition at line 695 of file loadmodel.cpp.

697 {
698  TopAbs_ShapeEnum stype = shape.ShapeType();
699  bool ret = false;
700  data.hasSolid = false;
701 
702  switch( stype )
703  {
704  case TopAbs_COMPOUND:
705  case TopAbs_COMPSOLID:
706  if( processComp( shape, data, parent, items ) )
707  ret = true;
708  break;
709 
710  case TopAbs_SOLID:
711  if( processSolid( shape, data, parent, items ) )
712  ret = true;
713  break;
714 
715  case TopAbs_SHELL:
716  if( processShell( shape, data, parent, items, NULL ) )
717  ret = true;
718  break;
719 
720  case TopAbs_FACE:
721  if( processFace( TopoDS::Face( shape ), data, parent, items, NULL ) )
722  ret = true;
723  break;
724 
725  default:
726  break;
727  }
728 
729  return ret;
730 }
bool processSolid(const TopoDS_Shape &shape, DATA &data, SGNODE *parent, std::vector< SGNODE * > *items)
Definition: loadmodel.cpp:554
#define NULL
bool processFace(const TopoDS_Face &face, DATA &data, SGNODE *parent, std::vector< SGNODE * > *items, Quantity_Color *color)
Definition: loadmodel.cpp:733
bool hasSolid
Definition: loadmodel.cpp:116
bool processComp(const TopoDS_Shape &shape, DATA &data, SGNODE *parent, std::vector< SGNODE * > *items)
Definition: loadmodel.cpp:631
bool processShell(const TopoDS_Shape &shape, DATA &data, SGNODE *parent, std::vector< SGNODE * > *items, Quantity_Color *color)
Definition: loadmodel.cpp:536

References DATA::hasSolid, NULL, processComp(), processFace(), processShell(), and processSolid().

Referenced by LoadModel().

◆ processShell()

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

Definition at line 536 of file loadmodel.cpp.

538 {
539  TopoDS_Iterator it;
540  bool ret = false;
541 
542  for( it.Initialize( shape, false, false ); it.More(); it.Next() )
543  {
544  const TopoDS_Face& face = TopoDS::Face( it.Value() );
545 
546  if( processFace( face, data, parent, items, color ) )
547  ret = true;
548  }
549 
550  return ret;
551 }
int color
Definition: DXF_plotter.cpp:61
bool processFace(const TopoDS_Face &face, DATA &data, SGNODE *parent, std::vector< SGNODE * > *items, Quantity_Color *color)
Definition: loadmodel.cpp:733

References color, and processFace().

Referenced by processComp(), processNode(), and processSolid().

◆ processSolid()

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

Definition at line 554 of file loadmodel.cpp.

556 {
557  TDF_Label label = data.m_assy->FindShape( shape, Standard_False );
558 
559  data.hasSolid = true;
560  std::string partID;
561  Quantity_Color col;
562  Quantity_Color* lcolor = NULL;
563 
564  if( label.IsNull() )
565  {
566  static int i = 0;
567  std::ostringstream ostr;
568  ostr << "KMISC_" << i++;
569  partID = ostr.str();
570  }
571  else
572  {
573  getTag( label, partID );
574 
575 
576  if( getColor( data, label, col ) )
577  lcolor = &col;
578  }
579 
580  TopoDS_Iterator it;
581  IFSG_TRANSFORM childNode( parent );
582  SGNODE* pptr = childNode.GetRawPtr();
583  const TopLoc_Location& loc = shape.Location();
584  bool ret = false;
585 
586  if( !loc.IsIdentity() )
587  {
588  gp_Trsf T = loc.Transformation();
589  gp_XYZ coord = T.TranslationPart();
590  childNode.SetTranslation( SGPOINT( coord.X(), coord.Y(), coord.Z() ) );
591  gp_XYZ axis;
592  Standard_Real angle;
593 
594  if( T.GetRotation( axis, angle ) )
595  childNode.SetRotation( SGVECTOR( axis.X(), axis.Y(), axis.Z() ), angle );
596  }
597 
598  std::vector< SGNODE* >* component = NULL;
599 
600  if( !partID.empty() )
601  data.GetShape( partID, component );
602 
603  if( component )
604  {
605  addItems( pptr, component );
606 
607  if( NULL != items )
608  items->push_back( pptr );
609  }
610 
611  // instantiate the solid
612  std::vector< SGNODE* > itemList;
613 
614  for( it.Initialize( shape, false, false ); it.More(); it.Next() )
615  {
616  const TopoDS_Shape& subShape = it.Value();
617 
618  if( processShell( subShape, data, pptr, &itemList, lcolor ) )
619  ret = true;
620  }
621 
622  if( !ret )
623  childNode.Destroy();
624  else if( NULL != items )
625  items->push_back( pptr );
626 
627  return ret;
628 }
T
enum T contains all this lexer's tokens.
SGNODE represents the base class of all Scene Graph nodes.
Definition: sg_node.h:76
#define NULL
void getTag(TDF_Label &label, std::string &aTag)
Definition: loadmodel.cpp:304
bool getColor(DATA &data, TDF_Label label, Quantity_Color &color)
Definition: loadmodel.cpp:344
bool hasSolid
Definition: loadmodel.cpp:116
void addItems(SGNODE *parent, std::vector< SGNODE * > *lp)
Definition: loadmodel.cpp:365
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
IFSG_TRANSFORM is the wrapper for the VRML compatible TRANSFORM block class SCENEGRAPH.
bool GetShape(const std::string &id, std::vector< SGNODE * > *&listPtr)
Definition: loadmodel.cpp:199
bool processShell(const TopoDS_Shape &shape, DATA &data, SGNODE *parent, std::vector< SGNODE * > *items, Quantity_Color *color)
Definition: loadmodel.cpp:536

References addItems(), PNS::angle(), IFSG_NODE::Destroy(), getColor(), IFSG_NODE::GetRawPtr(), DATA::GetShape(), getTag(), DATA::hasSolid, NULL, processShell(), IFSG_TRANSFORM::SetRotation(), and IFSG_TRANSFORM::SetTranslation().

Referenced by processComp(), and processNode().

◆ readIGES()

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

Definition at line 390 of file loadmodel.cpp.

391 {
392  IGESCAFControl_Reader reader;
393  IFSelect_ReturnStatus stat = reader.ReadFile( fname );
394  reader.PrintCheckLoad( Standard_False, IFSelect_ItemsByEntity );
395 
396  if( stat != IFSelect_RetDone )
397  return false;
398 
399  // Enable file-defined shape precision
400  if( !Interface_Static::SetIVal( "read.precision.mode", 0 ) )
401  return false;
402 
403  // set other translation options
404  reader.SetColorMode(true); // use model colors
405  reader.SetNameMode(false); // don't use IGES label names
406  reader.SetLayerMode(false); // ignore LAYER data
407 
408  if ( !reader.Transfer( m_doc ) )
409  return false;
410 
411  // are there any shapes to translate?
412  if( reader.NbShapes() < 1 )
413  return false;
414 
415  return true;
416 }

Referenced by LoadModel().

◆ readSTEP()

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

Definition at line 419 of file loadmodel.cpp.

420 {
421  STEPCAFControl_Reader reader;
422  IFSelect_ReturnStatus stat = reader.ReadFile( fname );
423 
424  if( stat != IFSelect_RetDone )
425  return false;
426 
427  // Enable user-defined shape precision
428  if( !Interface_Static::SetIVal( "read.precision.mode", 1 ) )
429  return false;
430 
431  // Set the shape conversion precision to USER_PREC (default 0.0001 has too many triangles)
432  if( !Interface_Static::SetRVal( "read.precision.val", USER_PREC ) )
433  return false;
434 
435  // set other translation options
436  reader.SetColorMode(true); // use model colors
437  reader.SetNameMode(false); // don't use label names
438  reader.SetLayerMode(false); // ignore LAYER data
439 
440  if ( !reader.Transfer( m_doc ) )
441  {
442  m_doc->Close();
443  return false;
444  }
445 
446  // are there any shapes to translate?
447  if( reader.NbRootsForTransfer() < 1 )
448  return false;
449 
450  return true;
451 }
#define USER_PREC
Definition: loadmodel.cpp:80

References USER_PREC.

Referenced by LoadModel().