0

その形状の各面が face1、face 2 などの異なるパッチ名を持つ特定の形状の .stl ファイルを作成したいと考えています。これは、opencascade で StlAPI_Writer および RWStl クラスをオーバーライドすることによって行いました。そのために、file.Build メソッドの代わりに file.Append メソッドを使用しました。しかし、既存のファイルに .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
  }

これは機能するはずですが、追加以外のものを使用する場合は、より簡単なバリアントにアクセスできる必要があります (書き込みまたは追加のようなものですが、ファイルの書き換えを指定するパラメーターを使用することもできます)。

HTH、JP

于 2011-07-15T09:10:39.403 に答える