0

我想为特定形状创建一个 .stl 文件,其中该形状的每个面都有不同的补丁名称,如 face1、face 2 等。我通过覆盖 opencascade 中的 StlAPI_Writer 和 RWStl 类来完成此操作。我使用了 file.Append 方法而不是 file.Build 方法来做到这一点。但是当我将 .stl 文件保存在一个已经存在的文件中时,我遇到了一个问题,它会将数据附加到不正确的现有文件中。我想删除文件中的现有数据,并为给定的形状逐面附加新数据。

请帮助我。

4

1 回答 1

0

您可以使用这个简单的功能:

#include <sys/stat.h>
#include <string>

using namespace std;    

bool FileExists(string strFilename) {
  struct stat stFileInfo;
  bool blnReturn;
  int intStat;

  // Attempt to get the file attributes
  intStat = stat(strFilename.c_str(),&stFileInfo);
  if(intStat == 0) {
    // We were able to get the file attributes
    // so the file obviously exists.
    blnReturn = true;
  } else {
    // We were not able to get the file attributes.
    // This may mean that we don't have permission to
    // access the folder which contains this file. If you
    // need to do that level of checking, lookup the
    // return values of stat which will give you
    // more details on why stat failed.
    blnReturn = false;
  }

  return(blnReturn);
}

我假设您使用SaveFileDialogue类。在这种情况下,您可以像这样处理对话的返回结果:

  if ( saveFileDialog.ShowDialog() == ::DialogResult::OK )  {
     if ( FileExist(saveFileDialog.FileName) )  {
        // erase the file
     }
     // write the code using the Append function
  }

这应该可行,但是如果您使用 Append 以外的其他内容(例如 Write 甚至可能是 Append 但带有指定重写文件的参数),则必须可以访问更简单的变体

HTH, 太平绅士

于 2011-07-15T09:10:39.403 回答