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 166bda9b6d0287516560df662ddce0a020ba61d0..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());
@@ -89,7 +90,7 @@ void ExchangePlugin_ExportFeature::execute()
   AttributeSelectionListPtr aSelectionListAttr =
       this->selectionList(ExchangePlugin_ExportFeature::SELECTION_LIST_ID());
   std::list<std::shared_ptr<GeomAPI_Shape> > aShapes;
-  for ( int i = 0, aSize = aSelectionListAttr->size(); i < aSize; ++i ) {
+  for (int i = 0, aSize = aSelectionListAttr->size(); i < aSize; ++i) {
     aShapes.push_back(aSelectionListAttr->value(i)->value());
   }
   std::shared_ptr<GeomAPI_Shape> aShape =
@@ -98,35 +99,41 @@ void ExchangePlugin_ExportFeature::execute()
   exportFile(aFilePath, aFormat, aShape);
 }
 
-std::list<std::string> ExchangePlugin_ExportFeature::getFormats() const
-{
-  // This value is a copy of string_list attribute of format_choice in plugin-Exchange.xml
-  // XPath:plugin-Exchange.xml:string(//*[@id="format_choice"]/@string_list)
-  std::string aFormats = "BREP STEP IGES-5.1 IGES-5.3";
-  return ExchangePlugin_Tools::split(aFormats, ' ');
-}
-
 bool ExchangePlugin_ExportFeature::exportFile(const std::string& theFileName,
                                               const std::string& theFormat,
                                               std::shared_ptr<GeomAPI_Shape> theShape)
 {
   // retrieve the file and plugin library names
   TCollection_AsciiString aFileName(theFileName.c_str());
-  OSD_Path aPath(aFileName);
   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;
-  TDF_Label anUnknownLabel = TDF_Label();
-
   TopoDS_Shape aShape(theShape->impl<TopoDS_Shape>());
   bool aResult = false;
   if (aFormatName == "BREP") {
-    aResult = BREPExport::Export(aFileName, aFormatName, aShape, anError, anUnknownLabel);
+    aResult = BREPExport::Export(aFileName, aFormatName, aShape, anError);
   } else if (aFormatName == "STEP") {
-    aResult = STEPExport::Export(aFileName, aFormatName, aShape, anError, anUnknownLabel);
+    aResult = STEPExport::Export(aFileName, aFormatName, aShape, anError);
   } else if (aFormatName.SubString(1, 4) == "IGES") {
-    aResult = IGESExport::Export(aFileName, aFormatName, aShape, anError, anUnknownLabel);
+    aResult = IGESExport::Export(aFileName, aFormatName, aShape, anError);
   } else {
     anError = TCollection_AsciiString("Unsupported format ") + aFormatName;
   }