PropertyPartShape: fix brep shape saving without copy
This commit is contained in:
@@ -43,6 +43,7 @@
|
||||
# include <gp_Trsf.hxx>
|
||||
#endif
|
||||
|
||||
#include <OSD_OpenFile.hxx>
|
||||
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Writer.h>
|
||||
@@ -264,6 +265,46 @@ void PropertyPartShape::Restore(Base::XMLReader &reader)
|
||||
}
|
||||
}
|
||||
|
||||
// The following two functions are copied from OCCT BRepTools.cxx and modified
|
||||
// to disable saving of triangulation
|
||||
//
|
||||
static void BRepTools_Write(const TopoDS_Shape& Sh, Standard_OStream& S) {
|
||||
BRepTools_ShapeSet SS(Standard_False);
|
||||
// SS.SetProgress(PR);
|
||||
SS.Add(Sh);
|
||||
SS.Write(S);
|
||||
SS.Write(Sh,S);
|
||||
}
|
||||
static Standard_Boolean BRepTools_Write(const TopoDS_Shape& Sh,
|
||||
const Standard_CString File)
|
||||
{
|
||||
ofstream os;
|
||||
OSD_OpenStream(os, File, ios::out);
|
||||
if (!os.rdbuf()->is_open()) return Standard_False;
|
||||
|
||||
Standard_Boolean isGood = (os.good() && !os.eof());
|
||||
if(!isGood)
|
||||
return isGood;
|
||||
|
||||
BRepTools_ShapeSet SS(Standard_False);
|
||||
// SS.SetProgress(PR);
|
||||
SS.Add(Sh);
|
||||
|
||||
os << "DBRep_DrawableShape\n"; // for easy Draw read
|
||||
SS.Write(os);
|
||||
isGood = os.good();
|
||||
if(isGood )
|
||||
SS.Write(Sh,os);
|
||||
os.flush();
|
||||
isGood = os.good();
|
||||
|
||||
errno = 0;
|
||||
os.close();
|
||||
isGood = os.good() && isGood && !errno;
|
||||
|
||||
return isGood;
|
||||
}
|
||||
|
||||
void PropertyPartShape::SaveDocFile (Base::Writer &writer) const
|
||||
{
|
||||
// If the shape is empty we simply store nothing. The file size will be 0 which
|
||||
@@ -275,7 +316,7 @@ void PropertyPartShape::SaveDocFile (Base::Writer &writer) const
|
||||
TopoDS_Shape myShape;
|
||||
auto hGrp = App::GetApplication().GetParameterGroupByPath(
|
||||
"User parameter:BaseApp/Preferences/Mod/Part/General");
|
||||
if(hGrp->GetBool("CopyShapeOnSave",true)) {
|
||||
if(hGrp->GetBool("CopyShapeOnSave",false)) {
|
||||
BRepBuilderAPI_Copy copy(_Shape.getShape());
|
||||
myShape = copy.Shape();
|
||||
BRepTools::Clean(myShape); // remove triangulation
|
||||
@@ -295,7 +336,7 @@ void PropertyPartShape::SaveDocFile (Base::Writer &writer) const
|
||||
// we may run into some problems on the Linux platform
|
||||
static Base::FileInfo fi(App::Application::getTempFileName());
|
||||
|
||||
if (!BRepTools::Write(myShape,(const Standard_CString)fi.filePath().c_str())) {
|
||||
if (!BRepTools_Write(myShape,(const Standard_CString)fi.filePath().c_str())) {
|
||||
// Note: Do NOT throw an exception here because if the tmp. file could
|
||||
// not be created we should not abort.
|
||||
// We only print an error message but continue writing the next files to the
|
||||
@@ -338,7 +379,7 @@ void PropertyPartShape::SaveDocFile (Base::Writer &writer) const
|
||||
fi.deleteFile();
|
||||
}
|
||||
else {
|
||||
BRepTools::Write(myShape, writer.Stream());
|
||||
BRepTools_Write(myShape, writer.Stream());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user