+// Copyright (c) 1999-2014 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+
#include <Standard_Stream.hxx>
#include <VrmlAPI_Writer.ixx>
#include <Vrml_Material.hxx>
#include <Vrml_Instancing.hxx>
#include <Vrml_Separator.hxx>
#include <VrmlConverter_WFDeflectionShape.hxx>
+#include <VrmlData_Scene.hxx>
+#include <VrmlData_ShapeConvert.hxx>
+#include <OSD_OpenFile.hxx>
+#include <TopExp_Explorer.hxx>
+#include <TopAbs_ShapeEnum.hxx>
+#include <TopoDS.hxx>
+#include <TopoDS_Face.hxx>
+#include <Poly_Triangulation.hxx>
+#include <BRep_Tool.hxx>
VrmlAPI_Writer::VrmlAPI_Writer()
{
return myUnfreeBoundsMaterial;
}
-void VrmlAPI_Writer::Write(const TopoDS_Shape& aShape,const Standard_CString aFile) const
+void VrmlAPI_Writer::Write(const TopoDS_Shape& aShape,const Standard_CString aFile, const Standard_Integer aVersion) const
+{
+ if (aVersion == 1)
+ write_v1(aShape, aFile);
+ else if (aVersion == 2)
+ write_v2(aShape, aFile);
+}
+
+void VrmlAPI_Writer::write_v1(const TopoDS_Shape& aShape,const Standard_CString aFile) const
{
OSD_Path thePath(aFile);
TCollection_AsciiString theFile;thePath.SystemName(theFile);
ofstream outfile;
- outfile.open(theFile.ToCString(), ios::out);
+ OSD_OpenStream(outfile, theFile.ToCString(), ios::out);
Handle(VrmlConverter_IsoAspect) ia = new VrmlConverter_IsoAspect; // UIso
Handle(VrmlConverter_IsoAspect) ia1 = new VrmlConverter_IsoAspect; //VIso
ia->SetMaterial(myUisoMaterial);
TopTools_Array1OfShape Shapes(1,1);
Shapes.SetValue(1,aShape);
+ // Check shape tesselation
+ TopExp_Explorer anExp (aShape, TopAbs_FACE);
+ TopLoc_Location aLoc;
+ Standard_Boolean hasTriangles = Standard_False;
+ for (; anExp.More(); anExp.Next())
+ {
+ const TopoDS_Face& aFace = TopoDS::Face (anExp.Current());
+ if (!aFace.IsNull())
+ {
+ Handle(Poly_Triangulation) aTri =
+ BRep_Tool::Triangulation (aFace, aLoc);
+
+ if (!aTri.IsNull())
+ {
+ hasTriangles = Standard_True;
+ break;
+ }
+ }
+ }
+
//=========================================
//---- Definition of data for Projector
//=========================================
projector1->Add(outfile);
Vrml_Separator S2;
S2.Print(outfile);
- if (myRepresentation == VrmlAPI_ShadedRepresentation || myRepresentation == VrmlAPI_BothRepresentation)
+ if ( (myRepresentation == VrmlAPI_ShadedRepresentation || myRepresentation == VrmlAPI_BothRepresentation) && hasTriangles)
{
Vrml_Group Group1;
Group1.Print(outfile);
S1.Print(outfile);
}
+void VrmlAPI_Writer::write_v2(const TopoDS_Shape& aShape,const Standard_CString aFile) const
+{
+ Standard_Boolean anExtFace = Standard_False;
+ if(myRepresentation == VrmlAPI_ShadedRepresentation || myRepresentation == VrmlAPI_BothRepresentation)
+ anExtFace = Standard_True;
+
+ Standard_Boolean anExtEdge = Standard_False;
+ if(myRepresentation == VrmlAPI_WireFrameRepresentation|| myRepresentation == VrmlAPI_BothRepresentation)
+ anExtEdge = Standard_True;
+
+ VrmlData_Scene aScene;
+ VrmlData_ShapeConvert aConv(aScene);
+ aConv.AddShape(aShape);
+ aConv.Convert(anExtFace, anExtEdge);
+
+ filebuf aFoc;
+ ostream outStream (&aFoc);
+ if (aFoc.open (aFile, ios::out))
+ outStream << aScene;
+}