How to deal with “Standard_OStream or Standard_CString” When I want to export a “BREP” file? #170
-
Hello! |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 2 replies
-
I believe the |
Beta Was this translation helpful? Give feedback.
-
We use opencascade.js to write BREP. Now the question is : though BRepTools.Write_3 return "true", we don't know whether the file "a.brep" is created or not, since we didn't find "a.brep" in the specified file path. The code is below:
Thanks for help! |
Beta Was this translation helpful? Give feedback.
-
Hi,Please look here,Creating Custom Builds | OpenCascade.js (ocjs.org)
additionalCppCode: | #include <BRepMesh_IncrementalMesh.hxx> #include <BRep_Builder.hxx> #include <BRepTools.hxx> #include <string> #include <iostream> #include <sstream> class OccUtils { private: OccUtils() {} public: static std::string ShapeToString(const TopoDS_Shape& shape) { std::ostringstream oss(std::ios_base::out); BRepTools::Write(shape, oss); return oss.str(); } static TopoDS_Shape ShapeFromString(const std::string& str) { TopoDS_Shape shape; BRep_Builder brepBuilder; std::istringstream iss(str, std::ios_base::in); BRepTools::Read(shape, iss, brepBuilder); return shape; } };
You use new opencascade.js to write BREP!
var shape = createSquare(this.openCascade, 10, 10, 10, 360, 1);var str = OccUtils.ShapeToString(shape);console.log(str)
------------------ 原始邮件 ------------------
发件人: "donalffons/opencascade.js" ***@***.***>;
发送时间: 2023年5月30日(星期二) 下午4:43
***@***.***>;
***@***.******@***.***>;
主题: Re: [donalffons/opencascade.js] How to deal with “Standard_OStream or Standard_CString” When I want to export a “BREP” file? (Discussion #170)
We use opencascade.js to write BREP. Now the question is : though BRepTools.Write_3 return "true", we don't know whether the file "a.brep" is created or not, since we didn't find "a.brep" in the specified file path. The code is below:
var shape = createSquare(this.openCascade, 10, 10, 10, 360, 1); var brepStr = "a.brep"; var theProgress = new this.openCascade.Message_ProgressRange_1(); var result = this.openCascade.BRepTools.Write_3(shape,brepStr,theProgress) console.log(result)
Thanks for help!
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
We found solution. Maybe js doesn't offer methods to write file to disk, and the file that occ.js created is storaged in occ.js buffer or something else, so we can't find file in our disk. But we can read the file and get the String like below:
Also, when you send a absolute path to BRepTools.Write_3(), it will return false, since js may not write file to you disk path. |
Beta Was this translation helpful? Give feedback.
-
Your solution is better than mine. I'll try yours, thank you!
…------------------ 原始邮件 ------------------
发件人: "donalffons/opencascade.js" ***@***.***>;
发送时间: 2023年5月31日(星期三) 中午1:34
***@***.***>;
***@***.******@***.***>;
主题: Re: [donalffons/opencascade.js] How to deal with “Standard_OStream or Standard_CString” When I want to export a “BREP” file? (Discussion #170)
We found solution. Maybe js doesn't offer methods to write file to disk, and the file that occ.js created is storaged in occ.js buffer or something else, so we can't find file in our disk. But we can read the file and get the String like below:
var theProgress = new this.openCascade.Message_ProgressRange_1(); var result = this.openCascade.BRepTools.Write_3(shape,"test",theProgress) let brep = this.openCascade.FS.readFile("/" + "test", { encoding:"utf8" }); this.openCascade.FS.unlink("/" + "test"); console.log(result) console.log(brep)
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
I believe the
Standard_OStream
is currently unusable (but if you or someone else has ideas / suggestions on how this could be made to work from JS, please share your ideas). However, theBRepTools.Write_3
method should work. You should be able to just pass a JS string for theStandard_CString theFile
argument - the conversion is done automatically.