+ add method to write/read BREP in binary format

This commit is contained in:
wmayer 2015-09-07 19:02:56 +02:00
parent 3665b77827
commit 7f9aa7b4a5
11 changed files with 88 additions and 1 deletions

View File

@ -104,6 +104,7 @@ if(OCC_FOUND)
TKSTL
TKShHealing
TKXSBase
TKBin
TKBool
TKBO
TKBRep

View File

@ -431,6 +431,7 @@ set(OCC_LIBRARIES
optimized TKSTL
optimized TKShHealing
optimized TKXSBase
optimized TKBin
optimized TKBool
optimized TKBO
optimized TKBRep
@ -456,6 +457,7 @@ set(OCC_DEBUG_LIBRARIES
debug TKSTLd
debug TKShHealingd
debug TKXSBased
debug TKBind
debug TKBoold
debug TKBOd
debug TKBRepd

View File

@ -305,6 +305,7 @@ set(OCC_LIBRARIES
TKSTL
TKShHealing
TKXSBase
TKBin
TKBool
TKBO
TKBRep

View File

@ -311,6 +311,7 @@ set(OCC_LIBRARIES
TKSTL
TKShHealing
TKXSBase
TKBin
TKBool
TKBO
TKBRep

View File

@ -356,6 +356,7 @@ set(OCC_LIBRARIES
optimized TKSTL
optimized TKShHealing
optimized TKXSBase
optimized TKBin
optimized TKBool
optimized TKXSBase
optimized TKBO
@ -391,6 +392,7 @@ set(OCC_DEBUG_LIBRARIES
debug TKSTLd
debug TKShHealingd
debug TKXSBased
debug TKBind
debug TKBoold
debug TKXSBased
debug TKBOd

View File

@ -371,6 +371,7 @@ set(OCC_LIBRARIES
optimized TKSTL
optimized TKShHealing
optimized TKXSBase
optimized TKBin
optimized TKBool
optimized TKBO
optimized TKBRep
@ -396,6 +397,7 @@ set(OCC_DEBUG_LIBRARIES
debug TKSTLd
debug TKShHealingd
debug TKXSBased
debug TKBind
debug TKBoold
debug TKBOd
debug TKBRepd

View File

@ -376,6 +376,7 @@ set(OCC_LIBRARIES
TKSTL
TKShHealing
TKXSBase
TKBin
TKBool
TKBO
TKBRep

View File

@ -144,6 +144,8 @@
# include <ShapeUpgrade_RemoveInternalWires.hxx>
# include <Standard_Version.hxx>
#endif
# include <BinTools.hxx>
# include <BinTools_ShapeSet.hxx>
# include <Poly_Polygon3D.hxx>
# include <Poly_PolygonOnTriangulation.hxx>
# include <BRepBuilderAPI_Sewing.hxx>
@ -670,6 +672,21 @@ void TopoShape::importBrep(std::istream& str)
}
}
void TopoShape::importBinary(std::istream& str)
{
BinTools_ShapeSet set;
set.Read(str);
Standard_Integer index;
BinTools::GetInteger(str, index);
try {
this->_Shape = set.Shape(index);
}
catch (Standard_Failure) {
throw Base::RuntimeError("Failed to read shape from binary stream");
}
}
void TopoShape::write(const char *FileName) const
{
Base::FileInfo File(FileName);
@ -758,6 +775,14 @@ void TopoShape::exportBrep(std::ostream& out) const
BRepTools::Write(this->_Shape, out);
}
void TopoShape::exportBinary(std::ostream& out)
{
BinTools_ShapeSet set;
Standard_Integer index = set.Add(this->_Shape);
set.Write(out);
BinTools::PutInteger(out, index);
}
void TopoShape::dump(std::ostream& out) const
{
BRepTools::Dump(this->_Shape, out);

View File

@ -124,10 +124,12 @@ public:
void importStep(const char *FileName);
void importBrep(const char *FileName);
void importBrep(std::istream&);
void importBinary(std::istream&);
void exportIges(const char *FileName) const;
void exportStep(const char *FileName) const;
void exportBrep(const char *FileName) const;
void exportBrep(std::ostream&) const;
void exportBinary(std::ostream&);
void exportStl (const char *FileName, double deflection) const;
void exportFaceSet(double, double, std::ostream&) const;
void exportLineSet(std::ostream&) const;

View File

@ -53,6 +53,11 @@ Sub-elements such as vertices, edges or faces are accessible as:
<UserDocu>Export the content of this shape to an BREP file. BREP is a CasCade native format.</UserDocu>
</Documentation>
</Methode>
<Methode Name="exportBinary" Const="true">
<Documentation>
<UserDocu>Export the content of this shape in binary format to a file.</UserDocu>
</Documentation>
</Methode>
<Methode Name="exportBrepToString" Const="true">
<Documentation>
<UserDocu>Export the content of this shape to a string in BREP format. BREP is a CasCade native format.</UserDocu>
@ -69,13 +74,18 @@ Sub-elements such as vertices, edges or faces are accessible as:
</Documentation>
</Methode>
<Methode Name="importBrep">
<Documentation>
<UserDocu>Load the shape from a file in BREP format.</UserDocu>
</Documentation>
</Methode>
<Methode Name="importBinary">
<Documentation>
<UserDocu>Import the content to this shape of a string in BREP format.</UserDocu>
</Documentation>
</Methode>
<Methode Name="importBrepFromString">
<Documentation>
<UserDocu>Import the content to this shape from a string in BREP format.</UserDocu>
<UserDocu>Load the shape from a string that keeps the content in BREP format.</UserDocu>
</Documentation>
</Methode>
<Methode Name="extrude" Const="true">

View File

@ -355,6 +355,26 @@ PyObject* TopoShapePy::exportBrep(PyObject *args)
Py_Return;
}
PyObject* TopoShapePy::exportBinary(PyObject *args)
{
char* input;
if (!PyArg_ParseTuple(args, "s", &input))
return NULL;
try {
// read binary brep
std::ofstream str(input, std::ios::out | std::ios::binary);
getTopoShapePtr()->exportBinary(str);
str.close();
}
catch (const Base::Exception& e) {
PyErr_SetString(PartExceptionOCCError,e.what());
return NULL;
}
Py_Return;
}
PyObject* TopoShapePy::dumpToString(PyObject *args)
{
if (!PyArg_ParseTuple(args, ""))
@ -430,6 +450,26 @@ PyObject* TopoShapePy::importBrep(PyObject *args)
Py_Return;
}
PyObject* TopoShapePy::importBinary(PyObject *args)
{
char* input;
if (!PyArg_ParseTuple(args, "s", &input))
return NULL;
try {
// read binary brep
std::ifstream str(input, std::ios::in | std::ios::binary);
getTopoShapePtr()->importBinary(str);
str.close();
}
catch (const Base::Exception& e) {
PyErr_SetString(PartExceptionOCCError,e.what());
return NULL;
}
Py_Return;
}
PyObject* TopoShapePy::importBrepFromString(PyObject *args)
{
char* input;