Salome HOME
Issue #529 : 4.07. Import IGES, export to BREP, STEP, IGES - Export IGES with versions
authorSergey POKHODENKO <sergey.pokhodenko@opencascade.com>
Fri, 15 May 2015 10:32:54 +0000 (13:32 +0300)
committerSergey POKHODENKO <sergey.pokhodenko@opencascade.com>
Tue, 19 May 2015 07:58:20 +0000 (10:58 +0300)
16 files changed:
src/ExchangePlugin/CMakeLists.txt
src/ExchangePlugin/ExchangePlugin.h
src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp
src/ExchangePlugin/ExchangePlugin_ExportFeature.h
src/ExchangePlugin/ExchangePlugin_Tools.cpp [new file with mode: 0644]
src/ExchangePlugin/ExchangePlugin_Tools.h [new file with mode: 0644]
src/ExchangePlugin/ExchangePlugin_Validators.cpp
src/ExchangePlugin/plugin-Exchange.xml
src/GeomAlgoAPI/GeomAlgoAPI_IGESExport.cpp
src/GeomAlgoAPI/GeomAlgoAPI_STEPExport.cpp
src/ModuleBase/ModuleBase_WidgetFileSelector.cpp
src/ModuleBase/ModuleBase_WidgetFileSelector.h
src/PartSet/CMakeLists.txt
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_WidgetFileSelector.cpp [new file with mode: 0644]
src/PartSet/PartSet_WidgetFileSelector.h [new file with mode: 0644]

index 2440dd1292b8674ef2119d89e305a370505d7f45..c31364d8f094bd016fd2d706f573f57368277fb1 100644 (file)
@@ -16,6 +16,7 @@ SET(PROJECT_HEADERS
     ExchangePlugin_ImportFeature.h
     ExchangePlugin_ExportFeature.h
     ExchangePlugin_Validators.h
+    ExchangePlugin_Tools.h
 )
 
 SET(PROJECT_SOURCES
@@ -23,6 +24,7 @@ SET(PROJECT_SOURCES
     ExchangePlugin_ImportFeature.cpp
     ExchangePlugin_ExportFeature.cpp
     ExchangePlugin_Validators.cpp
+    ExchangePlugin_Tools.cpp
 )
 
 SET(XML_RESOURCES
index 0c8f80b9577120adceb9f21eef3e24848be5f4a9..a6152af3ea0ac9d700f080086ff90981ff1a3dbd 100644 (file)
@@ -4,17 +4,17 @@
 #define EXCHANGEPLUGIN_H
 
 #if defined EXCHANGEPLUGIN_EXPORTS
-#if defined WIN32
-#define EXCHANGEPLUGIN_EXPORT              __declspec( dllexport )
+# if defined WIN32
+#  define EXCHANGEPLUGIN_EXPORT              __declspec( dllexport )
+# else
+#  define EXCHANGEPLUGIN_EXPORT
+# endif
 #else
-#define EXCHANGEPLUGIN_EXPORT
-#endif
-#else
-#if defined WIN32
-#define EXCHANGEPLUGIN_EXPORT              __declspec( dllimport )
-#else
-#define EXCHANGEPLUGIN_EXPORT
-#endif
+# if defined WIN32
+#  define EXCHANGEPLUGIN_EXPORT              __declspec( dllimport )
+# else
+#  define EXCHANGEPLUGIN_EXPORT
+# endif
 #endif
 
 #endif
index 5120fde5ef687b66dc61de71c514304db82022e2..166bda9b6d0287516560df662ddce0a020ba61d0 100644 (file)
@@ -8,6 +8,9 @@
  */
 
 #include <ExchangePlugin_ExportFeature.h>
+
+#include <ExchangePlugin_Tools.h>
+
 #include <GeomAlgoAPI_BREPExport.h>
 #include <GeomAlgoAPI_STEPExport.h>
 #include <GeomAlgoAPI_IGESExport.h>
 
 #include <GeomAPI_Shape.h>
 
-#include <ModelAPI_AttributeString.h>
 #include <ModelAPI_AttributeSelectionList.h>
+#include <ModelAPI_AttributeString.h>
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Document.h>
 #include <ModelAPI_Object.h>
 #include <ModelAPI_ResultBody.h>
+
 #include <TCollection_AsciiString.hxx>
 #include <TDF_Label.hxx>
 #include <TopoDS_Shape.hxx>
 #include <OSD_Path.hxx>
 
 #include <algorithm>
+#include <iterator>
 #include <string>
 #ifdef _DEBUG
 #include <iostream>
@@ -59,6 +64,7 @@ const std::string& ExchangePlugin_ExportFeature::getKind()
  */
 void ExchangePlugin_ExportFeature::initAttributes()
 {
+  data()->addAttribute(ExchangePlugin_ExportFeature::FILE_FORMAT_ID(), ModelAPI_AttributeString::typeId());
   data()->addAttribute(ExchangePlugin_ExportFeature::FILE_PATH_ID(), ModelAPI_AttributeString::typeId());
   data()->addAttribute(ExchangePlugin_ExportFeature::SELECTION_LIST_ID(), ModelAPI_AttributeSelectionList::typeId());
 }
@@ -68,54 +74,65 @@ void ExchangePlugin_ExportFeature::initAttributes()
  */
 void ExchangePlugin_ExportFeature::execute()
 {
-  AttributeStringPtr aFilePathAttr = std::dynamic_pointer_cast<ModelAPI_AttributeString>(
-      data()->attribute(ExchangePlugin_ExportFeature::FILE_PATH_ID()));
+  AttributeStringPtr aFormatAttr =
+      this->string(ExchangePlugin_ExportFeature::FILE_FORMAT_ID());
+  std::string aFormat = aFormatAttr->value();
+  if (aFormat.empty())
+    return;
+
+  AttributeStringPtr aFilePathAttr =
+      this->string(ExchangePlugin_ExportFeature::FILE_PATH_ID());
   std::string aFilePath = aFilePathAttr->value();
   if (aFilePath.empty())
     return;
 
   AttributeSelectionListPtr aSelectionListAttr =
-      std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(
-          data()->attribute(ExchangePlugin_ExportFeature::SELECTION_LIST_ID()));
-
+      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 ) {
-    std::shared_ptr<ModelAPI_AttributeSelection> anSelectionAttr = aSelectionListAttr->value(i);
-    aShapes.push_back(anSelectionAttr->value());
+    aShapes.push_back(aSelectionListAttr->value(i)->value());
   }
   std::shared_ptr<GeomAPI_Shape> aShape =
       GeomAlgoAPI_CompoundBuilder::compound(aShapes);
 
-  exportFile(aFilePath, aShape);
+  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 = aPath.Extension();
-  // ".brep" -> "BREP", TCollection_AsciiString are numbered from 1
-  aFormatName = aFormatName.SubString(2, aFormatName.Length());
-  aFormatName.UpperCase();
+  TCollection_AsciiString aFormatName(theFormat.c_str());
 
   // Perform the export
   TCollection_AsciiString anError;
   TDF_Label anUnknownLabel = TDF_Label();
 
   TopoDS_Shape aShape(theShape->impl<TopoDS_Shape>());
-  bool aResult = true;
+  bool aResult = false;
   if (aFormatName == "BREP") {
     aResult = BREPExport::Export(aFileName, aFormatName, aShape, anError, anUnknownLabel);
-  } else if (aFormatName == "STEP" || aFormatName == "STP") {
+  } else if (aFormatName == "STEP") {
     aResult = STEPExport::Export(aFileName, aFormatName, aShape, anError, anUnknownLabel);
-  } else if (aFormatName == "IGES") {
+  } else if (aFormatName.SubString(1, 4) == "IGES") {
     aResult = IGESExport::Export(aFileName, aFormatName, aShape, anError, anUnknownLabel);
+  } else {
+    anError = TCollection_AsciiString("Unsupported format ") + aFormatName;
   }
 
-  if ( !aResult ) {
-    const static std::string aShapeError =
+  if (!aResult) {
+    std::string aShapeError =
         "An error occurred while exporting " + theFileName + ": " + anError.ToCString();
     setError(aShapeError);
     return false;
index b308e12fcd18bbe905ba5f3871660790e9fa724f..fb45a27fc92f08420cc4633fa47a401ad8fa925f 100644 (file)
@@ -23,6 +23,12 @@ class ExchangePlugin_ExportFeature : public ModelAPI_Feature
     static const std::string MY_EXPORT_ID("Export");
     return MY_EXPORT_ID;
   }
+  /// attribute name of file format
+  inline static const std::string& FILE_FORMAT_ID()
+  {
+    static const std::string MY_FILE_FORMAT_ID("export_file_format");
+    return MY_FILE_FORMAT_ID;
+  }
   /// attribute name of file path
   inline static const std::string& FILE_PATH_ID()
   {
@@ -54,9 +60,10 @@ class ExchangePlugin_ExportFeature : public ModelAPI_Feature
   /// Reimplemented from ModelAPI_Feature::isPreviewNeeded(). Returns false.
   MODELAPI_EXPORT virtual bool isPreviewNeeded() const { return false; }
 
- protected:
+protected:
   /// Performs the export of the file
   EXCHANGEPLUGIN_EXPORT bool exportFile(const std::string& theFileName,
+                                        const std::string& theFormat,
                                         std::shared_ptr<GeomAPI_Shape> theShape);
 };
 
diff --git a/src/ExchangePlugin/ExchangePlugin_Tools.cpp b/src/ExchangePlugin/ExchangePlugin_Tools.cpp
new file mode 100644 (file)
index 0000000..c55689e
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+ * ExchangePlugin_Tools.cpp
+ *
+ *  Created on: May 15, 2015
+ *      Author: spo
+ */
+
+#include <ExchangePlugin_Tools.h>
+
+#include <sstream>
+
+std::list<std::string> ExchangePlugin_Tools::split(const std::string& theString, char theDelimiter)
+{
+  std::list<std::string> theResult;
+  std::istringstream aStream(theString);
+  std::string aSection;
+  while (std::getline(aStream, aSection, theDelimiter))
+    theResult.push_back(aSection);
+  return theResult;
+}
diff --git a/src/ExchangePlugin/ExchangePlugin_Tools.h b/src/ExchangePlugin/ExchangePlugin_Tools.h
new file mode 100644 (file)
index 0000000..b855207
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * ExchangePlugin_Tools.h
+ *
+ *  Created on: May 15, 2015
+ *      Author: spo
+ */
+
+#ifndef EXCHANGEPLUGIN_TOOLS_H_
+#define EXCHANGEPLUGIN_TOOLS_H_
+
+#include <ExchangePlugin.h>
+
+#include <list>
+#include <string>
+
+/**\class ExchangePlugin_Tools
+ * \ingroup Plugins
+ * \brief Internal tools for the plugin.
+ */
+class EXCHANGEPLUGIN_EXPORT ExchangePlugin_Tools {
+public:
+  /// Splits theString using theDelimiter.
+  static std::list<std::string> split(const std::string& theString,
+                                      char theDelimiter);
+
+};
+
+#endif /* EXCHANGEPLUGIN_TOOLS_H_ */
index 5a62fea8f048dd260110e69fc81d83bc46547948..16df0a1fe6b5946f4940f14cf3cad44b350882dd 100644 (file)
@@ -5,6 +5,9 @@
 // Author:      Vitaly SMETANNIKOV
 
 #include <ExchangePlugin_Validators.h>
+
+#include <ExchangePlugin_Tools.h>
+
 #include <ModelAPI_Feature.h>
 #include <ModelAPI_Object.h>
 #include <ModelAPI_Session.h>
@@ -12,7 +15,6 @@
 
 #include <list>
 #include <string>
-#include <sstream>
 #include <algorithm>
 
 bool ExchangePlugin_FormatValidator::parseFormats(const std::list<std::string>& theArguments,
@@ -27,12 +29,10 @@ bool ExchangePlugin_FormatValidator::parseFormats(const std::list<std::string>&
       result = false;
       continue;
     }
-    std::string aFormatList = anArg.substr(0, aSepPos);
-    std::transform(aFormatList.begin(), aFormatList.end(), aFormatList.begin(), toupper);
-    std::istringstream aStream(aFormatList);
-    std::string aFormat;
-    while (std::getline(aStream, aFormat, '|'))
-      outFormats.push_back(aFormat);
+    std::string aFormats = anArg.substr(0, aSepPos);
+    std::transform(aFormats.begin(), aFormats.end(), aFormats.begin(), toupper);
+    std::list<std::string> aFormatList = ExchangePlugin_Tools::split(aFormats, '|');
+    outFormats.insert(outFormats.end(), aFormatList.begin(), aFormatList.end());
   }
   return result;
 }
index 3c5111a6f9ba1fc53868d8b5d5e25c4e13da6cfd..f478491fed0f0406b29dafb904437cdbd3fb1143 100644 (file)
@@ -5,13 +5,13 @@
     <group id="Exchange">
       <feature id="Import" title="Import" tooltip="Import a file" icon=":icons/import.png">
         <file_selector id="import_file_selector" title="Import file" path="">
-          <validator id="ExchangePlugin_ImportFormat" parameters="BREP:BREPImport,STEP|STP:STEPImport,IGES:IGESImport" />
+          <validator id="ExchangePlugin_ImportFormat" parameters="BREP:BREP,STEP|STP:STEP,IGES:IGES" />
         </file_selector>
       </feature>
       <feature id="Export" title="Export" tooltip="Export to file" icon=":icons/export.png">
-        <file_selector id="export_file_selector" type="save" title="Export file" path="">
-          <validator id="ExchangePlugin_ExportFormat" parameters="BREP:BREPExport,STEP|STP:STEPExport,IGES:IGESExport" />
-        </file_selector>
+        <export_file_selector id="export_file_selector" type="save" title="Export file" path="">
+          <validator id="ExchangePlugin_ExportFormat" parameters="BREP:BREP,STEP|STP:STEP,IGES:IGES-5.1,IGES:IGES-5.3" />
+        </export_file_selector>
         <multi_selector id="selection_list" tooltip="Select a set of objects" type_choice="Vertices Edges Faces Solids" /> 
       </feature>
     </group>
index 4a7b52bf61db89d73a34a4d3e898272c4f142f82..425f58102edc13c6b2ee7a671e770618836c512f 100644 (file)
@@ -77,15 +77,21 @@ int KindOfBRep (const TopoDS_Shape& theShape)
 
 //=============================================================================
 //extern "C" {
+
 namespace IGESExport {
 
 bool Export(const TCollection_AsciiString& theFileName,
-            const TCollection_AsciiString&,
+            const TCollection_AsciiString& theFormatName,
             const TopoDS_Shape& theShape,
             TCollection_AsciiString& theError, const TDF_Label&)
 {
-  //TODO(spo): pass version as argument of the function
-  TCollection_AsciiString aVersion = "5.3";
+  // theFormatName expected "IGES-5.1", "IGES-5.3"...
+  TCollection_AsciiString aVersion = theFormatName.Token("-", 2);
+  #ifdef _DEBUG
+  if (!aVersion.IsEqual("5.1") || !aVersion.IsEqual("5.3"))
+    std::cout << "Warning: unrecognized version " << aVersion.ToCString()
+              << ". Default version: 5.1." << std::endl;
+  #endif
   // define, whether to write only faces (5.1 IGES format)
   // or shells and solids also (5.3 IGES format)
   int aBrepMode = 0;
@@ -124,7 +130,7 @@ bool Export(const TCollection_AsciiString& theFileName,
   // perform shape writing
   if( ICW.AddShape( theShape ) ) {
     ICW.ComputeModel();
-    return (bool)ICW.Write( theFileName.ToCString() );
+    return ICW.Write( theFileName.ToCString() );
   }
   return false;
 }
index 9454f4a06a112a74b42a14b90e1f566a843c9f4e..5cc71b056557a402f0ce7a83d08e1ec0b5f060e1 100644 (file)
@@ -9,11 +9,11 @@
 
 namespace STEPExport {
 
-bool Export (const TCollection_AsciiString& theFileName,
-             const TCollection_AsciiString& theFormatName,
-             const TopoDS_Shape& theShape,
-             TCollection_AsciiString&       theError,
-             const TDF_Label&               theShapeLabel)
+bool Export(const TCollection_AsciiString& theFileName,
+            const TCollection_AsciiString& theFormatName,
+            const TopoDS_Shape& theShape,
+            TCollection_AsciiString& theError,
+            const TDF_Label& theShapeLabel)
 {
   #ifdef _DEBUG
   std::cout << "Export STEP into file " << theFileName.ToCString() << std::endl;
index 139b3849a2f1caad2f5c1749febfe693cd141feb..5da22f5ebf6ccedab6b9e37ffc91377e0adea482 100644 (file)
@@ -111,11 +111,13 @@ bool ModuleBase_WidgetFileSelector::isCurrentPathValid()
 
 void ModuleBase_WidgetFileSelector::onPathSelectionBtn()
 {
-  QString aDefaultPath = myPathField->text().isEmpty() ? myDefaultPath : myPathField->text();
+  QString aDefaultPath = myPathField->text().isEmpty()
+      ? myDefaultPath
+      : QFileInfo(myPathField->text()).absolutePath();
   QString aFilter = filterString();
   QString aFileName = (myType == WFS_SAVE)
-      ? QFileDialog::getSaveFileName(this, myTitle, aDefaultPath, aFilter)
-      : QFileDialog::getOpenFileName(this, myTitle, aDefaultPath, aFilter);
+      ? QFileDialog::getSaveFileName(this, myTitle, aDefaultPath, aFilter, &mySelectedFilter)
+      : QFileDialog::getOpenFileName(this, myTitle, aDefaultPath, aFilter, &mySelectedFilter);
   if (!aFileName.isEmpty()) {
     myPathField->setText(aFileName);
   }
@@ -129,18 +131,15 @@ void ModuleBase_WidgetFileSelector::onPathChanged()
   emit valuesChanged();
 }
 
-QString ModuleBase_WidgetFileSelector::filterString() const
+QString ModuleBase_WidgetFileSelector::formatToFilter( const QString & theFormat )
 {
-  QStringList aResult;
-  QStringList aValidatorFormats = getValidatorFormats();
+  if (theFormat.isEmpty() && !theFormat.contains(":"))
+    return QString();
 
-  foreach(QString eachFormat, aValidatorFormats)  {
-    QStringList aFormatList = eachFormat.split("|");
-    aResult << QString("%1 files (%2)").arg(aFormatList.value(0))
-        .arg(QStringList(aFormatList).replaceInStrings(QRegExp("^(.*)$"), "*.\\1").join(" "));
-  }
-  aResult << QString("All files (*.*)");
-  return aResult.join(";;");
+  QStringList aExtesionList = theFormat.section(':', 0, 0).split("|");
+  QString aFormat = theFormat.section(':', 1, 1);
+  return QString("%1 files (%2)").arg(aFormat)
+      .arg(QStringList(aExtesionList).replaceInStrings(QRegExp("^(.*)$"), "*.\\1").join(" "));
 }
 
 QStringList ModuleBase_WidgetFileSelector::getValidatorFormats() const
@@ -154,18 +153,22 @@ QStringList ModuleBase_WidgetFileSelector::getValidatorFormats() const
   std::list<std::string> anArgumentList = allArguments.front();
   std::list<std::string>::const_iterator it = anArgumentList.begin();
   for (; it != anArgumentList.end(); ++it) {
-    QString aFormat = getFormat(*it);
-    if (!aFormat.isNull())
+    QString aFormat = QString::fromStdString(*it);
+    if (!aFormat.isEmpty())
       aResult << aFormat;
   }
   return aResult;
 }
 
-QString ModuleBase_WidgetFileSelector::getFormat( const std::string& theArgument ) const
+QString ModuleBase_WidgetFileSelector::filterString() const
 {
-  QString anArgument = QString::fromStdString(theArgument);
-  if (!anArgument.contains(":"))
-    return QString();
-  return anArgument.section(":", 0, 0).toUpper();
-}
+  QStringList aResult;
+  QStringList aValidatorFormats = getValidatorFormats();
 
+  foreach(const QString & eachFormat, aValidatorFormats) {
+    aResult << formatToFilter(eachFormat);
+  }
+  if (myType == WFS_OPEN)
+    aResult << QString("All files (*.*)");
+  return aResult.join(";;");
+}
index b89531cde6d414665d4aa0b58a6ce3b9efea863c..2ddc684acc015d75b8320b8f51d3b2a5f7d84157 100644 (file)
@@ -67,23 +67,26 @@ protected:
   /// \return True in success
   virtual bool storeValueCustom() const;
 
- protected:
-   /// Returns string containing formats
-  QString filterString() const;
+protected:
+  /// Converts format to filter string
+  static QString formatToFilter( const QString & theFormat );
 
   /// Returns list of validator formats
   QStringList getValidatorFormats() const;
 
-  /// Returns a format received from theArgument
-  QString getFormat( const std::string& theArgument ) const;
+  /// Returns string containing formats
+  QString filterString() const;
 
- private:
+protected:
    /// A control for path input
   QLineEdit* myPathField;
 
   /// A title of open file dialog box
   QString myTitle;
 
+  /// A current format
+  QString mySelectedFilter;
+
   /// A title of open file dialog box
   enum { WFS_OPEN, WFS_SAVE } myType;
 
index 048fba1e1e803786339f8a21d89e5fe809a51837..8c69ea96b1017673d68e69fa75d4b2277e5bc667 100644 (file)
@@ -18,6 +18,7 @@ SET(PROJECT_HEADERS
        PartSet_WidgetMultiSelector.h
        PartSet_WidgetPoint2dDistance.h
        PartSet_WidgetShapeSelector.h
+       PartSet_WidgetFileSelector.h
        PartSet_Filters.h
        PartSet_SketcherMgr.h
        PartSet_MenuMgr.h
@@ -38,6 +39,7 @@ SET(PROJECT_SOURCES
        PartSet_WidgetPoint2dAngle.cpp
        PartSet_WidgetPoint2dDistance.cpp
        PartSet_WidgetShapeSelector.cpp
+       PartSet_WidgetFileSelector.cpp
        PartSet_Filters.cpp
        PartSet_SketcherMgr.cpp
        PartSet_MenuMgr.cpp
index 6cc3f94e802a6a4ea4882a321be96e523c1bde82..4f4dd7fa1e32f3391b9f9a363fe4b5e7fdd7a4e7 100644 (file)
@@ -10,6 +10,7 @@
 #include "PartSet_WidgetPoint2dAngle.h"
 #include "PartSet_WidgetMultiSelector.h"
 #include "PartSet_WidgetEditor.h"
+#include "PartSet_WidgetFileSelector.h"
 #include "PartSet_SketcherMgr.h"
 #include "PartSet_MenuMgr.h"
 
@@ -495,6 +496,8 @@ ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& th
   }
   if (theType == WDG_DOUBLEVALUE_EDITOR) {
     aWgt = new PartSet_WidgetEditor(theParent, workshop(), theWidgetApi, theParentId);
+  } else if (theType == "export_file_selector") {
+    aWgt = new PartSet_WidgetFileSelector(theParent, workshop(), theWidgetApi, theParentId);
   } 
   return aWgt;
 }
@@ -735,4 +738,4 @@ void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMess
     }
     aLabel->setPalette(aPalet);
   }
-}
\ No newline at end of file
+}
diff --git a/src/PartSet/PartSet_WidgetFileSelector.cpp b/src/PartSet/PartSet_WidgetFileSelector.cpp
new file mode 100644 (file)
index 0000000..0b91dc0
--- /dev/null
@@ -0,0 +1,60 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+/*
+ * PartSet_WidgetFileSelector.cpp
+ *
+ *  Created on: May 18, 2015
+ *      Author: spo
+ */
+
+#include "PartSet_WidgetFileSelector.h"
+
+#include <ModelAPI_AttributeString.h>
+
+PartSet_WidgetFileSelector::PartSet_WidgetFileSelector(QWidget* theParent,
+                                                       ModuleBase_IWorkshop* theWorkshop,
+                                                       const Config_WidgetAPI* theData,
+                                                       const std::string& theParentId)
+: ModuleBase_WidgetFileSelector(theParent, theData, theParentId)
+, myWorkshop(theWorkshop)
+{
+}
+
+bool PartSet_WidgetFileSelector::restoreValue()
+{
+  // A rare case when plugin was not loaded.
+  if (!myFeature)
+    return false;
+
+  DataPtr aData = myFeature->data();
+  AttributeStringPtr aStringAttr = aData->string("export_file_format");
+  mySelectedFilter = formatToFilter(shortFormatToFullFormat(QString::fromStdString(aStringAttr->value())));
+
+  return ModuleBase_WidgetFileSelector::restoreValue();
+}
+
+bool PartSet_WidgetFileSelector::storeValueCustom() const
+{
+  // A rare case when plugin was not loaded.
+  if (!myFeature)
+    return false;
+
+  DataPtr aData = myFeature->data();
+  AttributeStringPtr aStringAttr = aData->string("export_file_format");
+  aStringAttr->setValue(filterToShortFormat(mySelectedFilter).toStdString());
+
+  return ModuleBase_WidgetFileSelector::storeValueCustom();
+}
+
+QString PartSet_WidgetFileSelector::filterToShortFormat( const QString & theFilter )
+{
+  return theFilter.section(' ', 0, 0);
+}
+
+QString PartSet_WidgetFileSelector::shortFormatToFullFormat( const QString & theFormat ) const
+{
+  foreach(const QString & eachFormat, getValidatorFormats())
+    if (filterToShortFormat(formatToFilter(eachFormat)) == theFormat)
+      return eachFormat;
+  return QString();
+}
diff --git a/src/PartSet/PartSet_WidgetFileSelector.h b/src/PartSet/PartSet_WidgetFileSelector.h
new file mode 100644 (file)
index 0000000..8d8c8ee
--- /dev/null
@@ -0,0 +1,57 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+/*
+ * PartSet_WidgetFileSelector.h
+ *
+ *  Created on: May 18, 2015
+ *      Author: spo
+ */
+
+#ifndef PARTSET_WIDGETFILESELECTOR_H_
+#define PARTSET_WIDGETFILESELECTOR_H_
+
+#include "PartSet.h"
+
+#include <ModuleBase_WidgetFileSelector.h>
+
+class ModuleBase_IWorkshop;
+
+/**
+* \ingroup Modules
+* Customization of ModuleBase_WidgetFileSelector in order to write
+* format of exported file.
+*/
+class PARTSET_EXPORT PartSet_WidgetFileSelector : public ModuleBase_WidgetFileSelector
+{
+  Q_OBJECT
+public:
+  /// Constructor
+  /// \param theParent the parent object
+  /// \param theWorkshop instance of workshop interface
+  /// \param theData the widget configuration. The attribute of the model widget is obtained from
+  /// \param theParentId is Id of a parent of the current attribute
+  PartSet_WidgetFileSelector(QWidget* theParent,
+                             ModuleBase_IWorkshop* theWorkshop,
+                             const Config_WidgetAPI* theData,
+                             const std::string& theParentId);
+
+  virtual ~PartSet_WidgetFileSelector() {}
+
+  /// Reimplemented from ModuleBase_WidgetFileSelector::restoreValue()
+  virtual bool restoreValue();
+
+protected:
+  /// Reimplemented from ModuleBase_WidgetFileSelector::storeValueCustom()
+  virtual bool storeValueCustom() const;
+
+  /// Returns a short format string of theFilter string
+  static QString filterToShortFormat( const QString & theFilter );
+
+  /// Returns a full format string for the short format
+  QString shortFormatToFullFormat( const QString & theShortFormat ) const;
+
+private:
+  ModuleBase_IWorkshop* myWorkshop; // the current workshop
+};
+
+#endif /* PARTSET_WIDGETFILESELECTOR_H_ */