Salome HOME
Fix for the issue #593: do not remove naming attribute, but use TNaming_Builder for...
[modules/shaper.git] / src / ExchangePlugin / ExchangePlugin_ExportFeature.cpp
index a67b57bccb115ce7d649bfd812bbf93b194ef1a3..6d3fc8a847a50c2fc54abd63f20eab758b615d2d 100644 (file)
@@ -77,8 +77,9 @@ void ExchangePlugin_ExportFeature::execute()
   AttributeStringPtr aFormatAttr =
       this->string(ExchangePlugin_ExportFeature::FILE_FORMAT_ID());
   std::string aFormat = aFormatAttr->value();
-  if (aFormat.empty())
-    return;
+  // Format may be empty. In this case look at extension.
+//  if (aFormat.empty())
+//    return;
 
   AttributeStringPtr aFilePathAttr =
       this->string(ExchangePlugin_ExportFeature::FILE_PATH_ID());
@@ -106,6 +107,23 @@ bool ExchangePlugin_ExportFeature::exportFile(const std::string& theFileName,
   TCollection_AsciiString aFileName(theFileName.c_str());
   TCollection_AsciiString aFormatName(theFormat.c_str());
 
+  if (theFormat.empty()) { // look at extension
+    OSD_Path aPath(aFileName);
+    TCollection_AsciiString anExtension = aPath.Extension();
+    // ".brep" -> "BREP", TCollection_AsciiString are numbered from 1
+    anExtension = anExtension.SubString(2, anExtension.Length());
+    anExtension.UpperCase();
+    if (anExtension == "BREP" || anExtension == "BRP") {
+      aFormatName = "BREP";
+    } else if (anExtension == "STEP" || anExtension == "STP") {
+      aFormatName = "STEP";
+    } else if (anExtension == "IGES" || anExtension == "IGS") {
+      aFormatName = "IGES-5.1";
+    } else {
+      aFormatName = anExtension;
+    }
+  }
+
   // Perform the export
   TCollection_AsciiString anError;
   TopoDS_Shape aShape(theShape->impl<TopoDS_Shape>());