]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #529 : 4.07. Import IGES, export to BREP, STEP, IGES - Export IGES
authorSergey POKHODENKO <sergey.pokhodenko@opencascade.com>
Thu, 14 May 2015 11:25:27 +0000 (14:25 +0300)
committerSergey POKHODENKO <sergey.pokhodenko@opencascade.com>
Tue, 19 May 2015 07:58:19 +0000 (10:58 +0300)
15 files changed:
src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp
src/ExchangePlugin/ExchangePlugin_ExportFeature.h
src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp
src/ExchangePlugin/ExchangePlugin_ImportFeature.h
src/ExchangePlugin/ExchangePlugin_Plugin.cpp
src/ExchangePlugin/ExchangePlugin_Validators.cpp
src/ExchangePlugin/ExchangePlugin_Validators.h
src/ExchangePlugin/plugin-Exchange.xml
src/GeomAlgoAPI/CMakeLists.txt
src/GeomAlgoAPI/GeomAlgoAPI_IGESExport.cpp [new file with mode: 0644]
src/GeomAlgoAPI/GeomAlgoAPI_IGESExport.h [new file with mode: 0644]
src/GeomAlgoAPI/GeomAlgoAPI_IGESImport.cpp
src/GeomAlgoAPI/GeomAlgoAPI_IGESImport.h
src/ModuleBase/ModuleBase_WidgetFileSelector.cpp
src/ModuleBase/ModuleBase_WidgetFileSelector.h

index 7af9d2af8d6f585392ed162b68f903998fbad168..57843ebc3ea5014fac06f08999a52aaf9bba5bb0 100644 (file)
 #include <ExchangePlugin_ExportFeature.h>
 //#include <GeomAlgoAPI_BREPExport.h>
 //#include <GeomAlgoAPI_STEPExport.h>
-//#include <GeomAlgoAPI_IGESExport.h>
+#include <GeomAlgoAPI_IGESExport.h>
 
-#include <GeomAPI_Shape.h>
 #include <Config_Common.h>
 #include <Config_PropManager.h>
 
+#include <GeomAlgoAPI_CompoundBuilder.h>
+
+#include <GeomAPI_Shape.h>
+
 #include <ModelAPI_AttributeString.h>
+#include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Document.h>
 #include <ModelAPI_Object.h>
@@ -56,6 +60,7 @@ const std::string& ExchangePlugin_ExportFeature::getKind()
 void ExchangePlugin_ExportFeature::initAttributes()
 {
   data()->addAttribute(ExchangePlugin_ExportFeature::FILE_PATH_ID(), ModelAPI_AttributeString::typeId());
+  data()->addAttribute(ExchangePlugin_ExportFeature::SELECTION_LIST_ID(), ModelAPI_AttributeSelectionList::typeId());
 }
 
 /*
@@ -66,15 +71,29 @@ void ExchangePlugin_ExportFeature::execute()
   AttributeStringPtr aFilePathAttr = std::dynamic_pointer_cast<ModelAPI_AttributeString>(
       data()->attribute(ExchangePlugin_ExportFeature::FILE_PATH_ID()));
   std::string aFilePath = aFilePathAttr->value();
-  if(aFilePath.empty())
+  if (aFilePath.empty())
     return;
-  exportFile(aFilePath);
+
+  AttributeSelectionListPtr aSelectionListAttr =
+      std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(
+          data()->attribute(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());
+  }
+  std::shared_ptr<GeomAPI_Shape> aShape =
+      GeomAlgoAPI_CompoundBuilder::compound(aShapes);
+
+  exportFile(aFilePath, aShape);
 }
 
-bool ExchangePlugin_ExportFeature::exportFile(const std::string& theFileName)
+bool ExchangePlugin_ExportFeature::exportFile(const std::string& theFileName,
+                                              std::shared_ptr<GeomAPI_Shape> theShape)
 {
   // retrieve the file and plugin library names
-  TCollection_AsciiString aFileName (theFileName.c_str());
+  TCollection_AsciiString aFileName(theFileName.c_str());
   OSD_Path aPath(aFileName);
   TCollection_AsciiString aFormatName = aPath.Extension();
   // ".brep" -> "BREP", TCollection_AsciiString are numbered from 1
@@ -85,50 +104,22 @@ bool ExchangePlugin_ExportFeature::exportFile(const std::string& theFileName)
   TCollection_AsciiString anError;
   TDF_Label anUnknownLabel = TDF_Label();
 
-  TopoDS_Shape aShape;
-//  if (aFormatName == "BREP") {
+  TopoDS_Shape aShape(theShape->impl<TopoDS_Shape>());
+  bool aResult = true;
+  if (aFormatName == "BREP") {
 //    aShape = BREPExport::Export(aFileName, aFormatName, anError, anUnknownLabel);
-//  } else if (aFormatName == "STEP" || aFormatName == "STP") {
+  } else if (aFormatName == "STEP" || aFormatName == "STP") {
 //    aShape = STEPExport::Export(aFileName, aFormatName, anError, anUnknownLabel);
-//  } else if (aFormatName == "IGES") {
-//    aShape = IGESExport::Export(aFileName, aFormatName, anError, anUnknownLabel);
-//  }
-//   // Check if shape is valid
-//  if ( aShape.IsNull() ) {
-//     const static std::string aShapeError =
-//       "An error occurred while exporting " + theFileName + ": " + anError.ToCString();
-//     setError(aShapeError);
-//     return false;
-//   }
-//
-//  // Pass the results into the model
-//  std::string anObjectName = aPath.Name().ToCString();
-//  data()->setName(anObjectName);
-//  std::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data());
-//  std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
-//  aGeomShape->setImpl(new TopoDS_Shape(aShape));
-//
-//  //LoadNamingDS of the exported shape
-//  loadNamingDS(aGeomShape, aResultBody);
-//
-//  setResult(aResultBody);
+  } else if (aFormatName == "IGES") {
+    aResult = IGESExport::Export(aFileName, aFormatName, aShape, anError, anUnknownLabel);
+  }
 
-  return true;
-}
+  if ( !aResult ) {
+    const static std::string aShapeError =
+        "An error occurred while exporting " + theFileName + ": " + anError.ToCString();
+    setError(aShapeError);
+    return false;
+  }
 
-//============================================================================
-void ExchangePlugin_ExportFeature::loadNamingDS(
-    std::shared_ptr<GeomAPI_Shape> theGeomShape,
-    std::shared_ptr<ModelAPI_ResultBody> theResultBody)
-{
-  //load result
-  theResultBody->store(theGeomShape);
-
-  int aTag(1);
-  std::string aNameMS = "Shape";
-  theResultBody->loadFirstLevel(theGeomShape, aNameMS, aTag);
-  //std::string aNameDE = "DiscEdges";
-  //theResultBody->loadDisconnectedEdges(theGeomShape, aNameDE, aTag);
-  //std::string aNameDV = "DiscVertexes";
-  //theResultBody->loadDisconnectedVertexes(theGeomShape, aNameDV, aTag); 
+  return true;
 }
index 94160a860721c53c5285dcd609ebac803e524970..b308e12fcd18bbe905ba5f3871660790e9fa724f 100644 (file)
 class ExchangePlugin_ExportFeature : public ModelAPI_Feature
 {
  public:
-  /// Extrusion kind
   inline static const std::string& ID()
   {
     static const std::string MY_EXPORT_ID("Export");
     return MY_EXPORT_ID;
   }
-  /// attribute name of referenced face
+  /// attribute name of file path
   inline static const std::string& FILE_PATH_ID()
   {
     static const std::string MY_FILE_PATH_ID("export_file_selector");
     return MY_FILE_PATH_ID;
   }
+  /// attribute name of selection list
+  inline static const std::string& SELECTION_LIST_ID()
+  {
+    static const std::string MY_SELECTION_LIST_ID("selection_list");
+    return MY_SELECTION_LIST_ID;
+  }
   /// default constructor
   EXCHANGEPLUGIN_EXPORT ExchangePlugin_ExportFeature();
   /// default destructor
@@ -51,12 +56,8 @@ class ExchangePlugin_ExportFeature : public ModelAPI_Feature
 
  protected:
   /// Performs the export of the file
-  EXCHANGEPLUGIN_EXPORT bool exportFile(const std::string& theFileName);
-
-private:
-  /// Loads Naming data structure to the document
-  void loadNamingDS(std::shared_ptr<GeomAPI_Shape> theGeomShape, 
-                    std::shared_ptr<ModelAPI_ResultBody> theResultBody);
+  EXCHANGEPLUGIN_EXPORT bool exportFile(const std::string& theFileName,
+                                        std::shared_ptr<GeomAPI_Shape> theShape);
 };
 
 #endif /* EXPORT_EXPORTFEATURE_H_ */
index 86d0fae393ae9a7d67d4365e683c51052a525bab..f5bf2bb11ac97ee686b6ef8b18daea22612cd5fc 100644 (file)
@@ -74,7 +74,7 @@ void ExchangePlugin_ImportFeature::execute()
 bool ExchangePlugin_ImportFeature::importFile(const std::string& theFileName)
 {
   // retrieve the file and plugin library names
-  TCollection_AsciiString aFileName (theFileName.c_str());
+  TCollection_AsciiString aFileName(theFileName.c_str());
   OSD_Path aPath(aFileName);
   TCollection_AsciiString aFormatName = aPath.Extension();
   // ".brep" -> "BREP", TCollection_AsciiString are numbered from 1
@@ -118,12 +118,12 @@ bool ExchangePlugin_ImportFeature::importFile(const std::string& theFileName)
 
 //============================================================================
 void ExchangePlugin_ImportFeature::loadNamingDS(
-                                   std::shared_ptr<GeomAPI_Shape> theGeomShape, 
-                                            std::shared_ptr<ModelAPI_ResultBody> theResultBody)
-{  
+    std::shared_ptr<GeomAPI_Shape> theGeomShape,
+    std::shared_ptr<ModelAPI_ResultBody> theResultBody)
+{
   //load result
   theResultBody->store(theGeomShape);
+
   int aTag(1);
   std::string aNameMS = "Shape";
   theResultBody->loadFirstLevel(theGeomShape, aNameMS, aTag);
index c0f259f457510583d5cc3a76a3d68bb50dbd6c89..b1fc310add5dbbae09f14ab85d9955e69fd972e1 100644 (file)
@@ -50,7 +50,7 @@ class ExchangePlugin_ImportFeature : public ModelAPI_Feature
   }
 
  protected:
-  /// POerforms the import of the file
+  /// Performs the import of the file
   EXCHANGEPLUGIN_EXPORT bool importFile(const std::string& theFileName);
 
 private:
index 94a55fd8fee0e46ad8dcdde579f0d1f11e0cd4b6..c843f6cc15cc133ff0b811851c816cf8029cedd0 100644 (file)
@@ -29,6 +29,8 @@ ExchangePlugin_Plugin::ExchangePlugin_Plugin()
   ModelAPI_ValidatorsFactory* aFactory = aSession->validators();
   aFactory->registerValidator("ExchangePlugin_ImportFormat",
                               new ExchangePlugin_ImportFormatValidator);
+  aFactory->registerValidator("ExchangePlugin_ExportFormat",
+                              new ExchangePlugin_ExportFormatValidator);
 
   // register construction properties
   //Config_PropManager::registerProp("Visualization", "import_feature_color", "Imported feature color",
index 5dc974e72a4cf7f793d8f5c18a5910d2909a224f..5a62fea8f048dd260110e69fc81d83bc46547948 100644 (file)
@@ -15,8 +15,8 @@
 #include <sstream>
 #include <algorithm>
 
-bool ExchangePlugin_ImportFormatValidator::parseFormats(const std::list<std::string>& theArguments,
-                                                        std::list<std::string>& outFormats)
+bool ExchangePlugin_FormatValidator::parseFormats(const std::list<std::string>& theArguments,
+                                                  std::list<std::string>& outFormats)
 {
   std::list<std::string>::const_iterator it = theArguments.begin();
   bool result = true;
@@ -37,32 +37,32 @@ bool ExchangePlugin_ImportFormatValidator::parseFormats(const std::list<std::str
   return result;
 }
 
-bool ExchangePlugin_ImportFormatValidator::isValid(const AttributePtr& theAttribute,
-                                                   const std::list<std::string>& theArguments) const
+bool ExchangePlugin_FormatValidator::isValid(const AttributePtr& theAttribute,
+                                             const std::list<std::string>& theArguments) const
 {
-  SessionPtr aMgr = ModelAPI_Session::get();
-  ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
-  if (theAttribute->isInitialized()) {
-    const AttributeStringPtr aStrAttr =
-        std::dynamic_pointer_cast<ModelAPI_AttributeString>(theAttribute);
-    if(!aStrAttr)
-      return false;
-    std::string aFileName = aStrAttr->value();
-    if (!aFileName.empty()) {
-      std::list<std::string> aFormats;
-      ExchangePlugin_ImportFormatValidator::parseFormats(theArguments, aFormats);
-      std::list<std::string>::const_iterator itFormats = aFormats.begin();
-      size_t aFileNameLen = aFileName.length();
-      std::transform(aFileName.begin(), aFileName.end(), aFileName.begin(), toupper);
-      // Is file name ends with the format
-      for (; itFormats != aFormats.end(); ++itFormats) {
-        size_t aFormatBeginPos = aFileNameLen - (*itFormats).length();
-        if (aFileName.compare(aFormatBeginPos, std::string::npos, *itFormats) == 0) {
-          return true;
-        }
-      }
+  if (!theAttribute->isInitialized())
+    return false;
+
+  const AttributeStringPtr aStrAttr =
+      std::dynamic_pointer_cast<ModelAPI_AttributeString>(theAttribute);
+  if (!aStrAttr)
+    return false;
+
+  std::string aFileName = aStrAttr->value();
+  if (aFileName.empty())
+    return false;
+
+  std::list<std::string> aFormats;
+  ExchangePlugin_FormatValidator::parseFormats(theArguments, aFormats);
+  std::list<std::string>::const_iterator itFormats = aFormats.begin();
+  size_t aFileNameLen = aFileName.length();
+  std::transform(aFileName.begin(), aFileName.end(), aFileName.begin(), toupper);
+  // Is file name ends with the format
+  for (; itFormats != aFormats.end(); ++itFormats) {
+    size_t aFormatBeginPos = aFileNameLen - (*itFormats).length();
+    if (aFileName.compare(aFormatBeginPos, std::string::npos, *itFormats) == 0) {
+      return true;
     }
   }
   return false;
 }
-
index 3f1bb793b76ca9adfeaec7b35912438d7409ca64..3e9ebb912383932058df32c67792741fd40a1062 100644 (file)
  * about which formats are supported and the extension of the associated files.
  * This validator filters out files that are out of this description.
  */
-class ExchangePlugin_ImportFormatValidator : public ModelAPI_AttributeValidator
+class ExchangePlugin_FormatValidator : public ModelAPI_AttributeValidator
 {
   /**
-   * Parses input arguments "BREP:BREPImport", "STEP:STEPImport"
-   * into list of file formats "BREP","STEP"
+   * Parses input arguments "BREP:BREPImport", "STEP|STP:STEPImport"
+   * into list of file formats "BREP","STEP","STP"
    * and list of corresponding plugins: "BREPImport", "STEPImport"
    */
   static bool parseFormats(const std::list<std::string>& theArguments,
@@ -34,8 +34,15 @@ public:
    */
   virtual bool isValid(const AttributePtr& theAttribute,
                        const std::list<std::string>& theArguments) const;
+};
 
+class ExchangePlugin_ImportFormatValidator : public ExchangePlugin_FormatValidator
+{
 
+};
+
+class ExchangePlugin_ExportFormatValidator : public ExchangePlugin_FormatValidator
+{
 
 };
 
index a389bcec15785cb781b0e3983b2291ea4f3fee59..3c5111a6f9ba1fc53868d8b5d5e25c4e13da6cfd 100644 (file)
@@ -9,9 +9,10 @@
         </file_selector>
       </feature>
       <feature id="Export" title="Export" tooltip="Export to file" icon=":icons/export.png">
-        <file_selector id="export_file_selector" title="Export file" path="">
-          <validator id="ExchangePlugin_ExportFormat" parameters="BREgi tP:BREPExport,STEP|STP:STEPExport,IGES:IGESExport" />
+        <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>
+        <multi_selector id="selection_list" tooltip="Select a set of objects" type_choice="Vertices Edges Faces Solids" /> 
       </feature>
     </group>
   </workbench>
index 944f43382d8b63483844458f6abbef342ea1502a..44dd3cb42af65031e1932d2b09585a1f7414f20c 100644 (file)
@@ -22,6 +22,7 @@ SET(PROJECT_HEADERS
     GeomAlgoAPI_BREPImport.h
     GeomAlgoAPI_STEPImport.h
     GeomAlgoAPI_IGESImport.h
+    GeomAlgoAPI_IGESExport.h
 )
 
 SET(PROJECT_SOURCES
@@ -40,6 +41,7 @@ SET(PROJECT_SOURCES
     GeomAlgoAPI_BREPImport.cpp
     GeomAlgoAPI_STEPImport.cpp
     GeomAlgoAPI_IGESImport.cpp
+    GeomAlgoAPI_IGESExport.cpp
 )
 
 SET(PROJECT_LIBRARIES
diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_IGESExport.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_IGESExport.cpp
new file mode 100644 (file)
index 0000000..4a7b52b
--- /dev/null
@@ -0,0 +1,134 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+#include <GeomAlgoAPI_IGESExport.h>
+
+//// KERNEL includes
+//#include <utilities.h>
+//#include <Basics_Utils.hxx>
+
+// OOCT includes
+#include <IGESControl_Controller.hxx>
+#include <IGESControl_Writer.hxx>
+#include <Interface_Static.hxx>
+
+#include <TopoDS_Shape.hxx>
+#include <TopoDS_Iterator.hxx>
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+/*!
+ *  KindOfBRep
+ *  \return 0 if theShape contains only simple entities (wires, edges and vertices),
+ *          1 if theShape contains only complex entities (shells, solids and compsolids)
+ *          2 if theShape contains only indifferent entities (faces)
+ *         -1 if theShape contains both simple and complex entities (and in this case it
+ *            cannot be saved without any loss neither in BRepMode == 0 nor in BRepMode == 1)
+ */
+//=============================================================================
+int KindOfBRep (const TopoDS_Shape& theShape)
+{
+  int aKind = 2;
+
+  switch (theShape.ShapeType())
+  {
+  case TopAbs_COMPOUND:
+    {
+      bool isSimple = false;
+      bool isComplex = false;
+      TopoDS_Iterator anIt (theShape, Standard_True, Standard_True);
+      for (; anIt.More(); anIt.Next()) {
+        TopoDS_Shape aS = anIt.Value();
+        int aKindSub = KindOfBRep(aS);
+        if (aKindSub == 0)
+          isSimple = true;
+        else if (aKindSub == 1)
+          isComplex = true;
+        else if (aKindSub == -1) {
+          return -1; // heterogeneous
+        }
+      }
+      if (isSimple && isComplex)
+        aKind = -1; // heterogeneous
+      else if (isSimple)
+        aKind = 0;
+      else if (isComplex)
+        aKind = 1;
+    }
+    break;
+  case TopAbs_COMPSOLID:
+  case TopAbs_SOLID:
+  case TopAbs_SHELL:
+    aKind = 1;
+    break;
+  case TopAbs_WIRE:
+  case TopAbs_EDGE:
+  case TopAbs_VERTEX:
+    aKind = 0;
+    break;
+  default:
+    aKind = 2;
+  }
+
+  return aKind;
+}
+
+//=============================================================================
+//extern "C" {
+namespace IGESExport {
+
+bool Export(const TCollection_AsciiString& theFileName,
+            const TCollection_AsciiString&,
+            const TopoDS_Shape& theShape,
+            TCollection_AsciiString& theError, const TDF_Label&)
+{
+  //TODO(spo): pass version as argument of the function
+  TCollection_AsciiString aVersion = "5.3";
+  // define, whether to write only faces (5.1 IGES format)
+  // or shells and solids also (5.3 IGES format)
+  int aBrepMode = 0;
+  if( aVersion.IsEqual( "5.3" ) )
+    aBrepMode = 1;
+
+  #ifdef _DEBUG
+  std::cout << "Export IGES into file " << theFileName.ToCString() << std::endl;
+  #endif
+
+  // Mantis issue 0021350: check being exported shape, as some stand-alone
+  // entities (edges, wires and vertices) cannot be saved in BRepMode
+  if( aBrepMode == 1 ) {
+    int aKind = KindOfBRep( theShape );
+    if( aKind == -1 ) {
+      theError = "EXPORT_IGES_HETEROGENEOUS_COMPOUND";
+      return false;
+    } else if( aKind == 2 )
+      aBrepMode = 1;
+    else
+      aBrepMode = aKind;
+  }
+
+//  // Set "C" numeric locale to save numbers correctly
+//  Kernel_Utils::Localizer loc;
+
+  // initialize writer
+  IGESControl_Controller::Init();
+  IGESControl_Writer ICW( "M", aBrepMode ); // export explicitly in meters
+  Interface_Static::SetCVal( "xstep.cascade.unit", "M" );
+
+  // 09.03.2010 skl for bug 0020726
+  // change default value "Average" to "Max"
+  Interface_Static::SetCVal( "write.precision.mode", "Max" );
+
+  // perform shape writing
+  if( ICW.AddShape( theShape ) ) {
+    ICW.ComputeModel();
+    return (bool)ICW.Write( theFileName.ToCString() );
+  }
+  return false;
+}
+
+}
+
+//}
diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_IGESExport.h b/src/GeomAlgoAPI/GeomAlgoAPI_IGESExport.h
new file mode 100644 (file)
index 0000000..7a7f28d
--- /dev/null
@@ -0,0 +1,30 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+/*
+ * GEOMALGOAPI_IGESExport.h
+ *
+ *  Created on: Dec 24, 2014
+ *      Author: sbh
+ */
+
+#ifndef GEOMALGOAPI_IGESEXPORT_H_
+#define GEOMALGOAPI_IGESEXPORT_H_
+
+#include <GeomAlgoAPI.h>
+
+#include <TCollection_AsciiString.hxx>
+#include <TopoDS_Shape.hxx>
+#include <TDF_Label.hxx>
+
+namespace IGESExport {
+
+/// Implementation of the import IGES files algorithms
+GEOMALGOAPI_EXPORT
+bool Export(const TCollection_AsciiString& theFileName,
+            const TCollection_AsciiString& theFormatName,
+            const TopoDS_Shape& theShape,
+            TCollection_AsciiString& theError, const TDF_Label&);
+
+}
+
+#endif /* GEOMALGOAPI_IGESEXPORT_H_ */
index cc46fda83e713cb9a4f3315176415938bd7e36fd..481c13521d08c225ddaa68bbb99b0f17d8888319 100644 (file)
@@ -21,25 +21,11 @@ TopoDS_Shape Import(const TCollection_AsciiString& theFileName,
   std::cout << "Import IGES from file " << theFileName << std::endl;
   #endif
   TopoDS_Shape aResShape;
-
-//  bool anIsIgnoreUnits = false;
-
   IGESControl_Reader aReader;
   try {
     IFSelect_ReturnStatus status = aReader.ReadFile( theFileName.ToCString() );
 
     if (status == IFSelect_RetDone) {
-//      if( anIsIgnoreUnits ) {
-//        // need re-scale a model, set UnitFlag to 'meter'
-//        Handle(IGESData_IGESModel) aModel =
-//          Handle(IGESData_IGESModel)::DownCast( aReader.Model() );
-//        if( !aModel.IsNull() ) {
-//          IGESData_GlobalSection aGS = aModel->GlobalSection();
-//          aGS.SetUnitFlag(6);
-//          aModel->SetGlobalSection(aGS);
-//        }
-//      }
-
       #ifdef _DEBUG
       std::cout << "ImportIGES : all Geometry Transfer" << std::endl;
       #endif
@@ -68,7 +54,7 @@ TopoDS_Shape Import(const TCollection_AsciiString& theFileName,
         default:
           theError = "Wrong format of the imported file. Can't import file.";
           break;
-        }
+      }
       aResShape.Nullify();
     }
   }
index 312b3fc1ef83d5c68c04ad25cbbc068540580785..c01f7c1d542675acc8dfd842a753450915da56ad 100644 (file)
@@ -3,8 +3,8 @@
 /*
  * GEOMALGOAPI_IGESImport.h
  *
- *  Created on: Dec 24, 2014
- *      Author: sbh
+ *  Created on: May 14, 2015
+ *      Author: spo
  */
 
 #ifndef GEOMALGOAPI_IGESIMPORT_H_
index f997592d15fae760edef41500a49dc33b5c04aac..c7fcacd11e278cd8036eaad8416098419a2666c4 100644 (file)
@@ -36,6 +36,7 @@ ModuleBase_WidgetFileSelector::ModuleBase_WidgetFileSelector(QWidget* theParent,
     : ModuleBase_ModelWidget(theParent, theData, theParentId)
 {
   myTitle = QString::fromStdString(theData->getProperty("title"));
+  myType = (theData->getProperty("type") == "save") ? WFS_SAVE : WFS_OPEN;
   myDefaultPath = QString::fromStdString(theData->getProperty("path"));
 
   QGridLayout* aMainLay = new QGridLayout(this);
@@ -68,7 +69,7 @@ ModuleBase_WidgetFileSelector::~ModuleBase_WidgetFileSelector()
 bool ModuleBase_WidgetFileSelector::storeValueCustom() const
 {
   // A rare case when plugin was not loaded. 
-  if(!myFeature)
+  if (!myFeature)
     return false;
   DataPtr aData = myFeature->data();
   AttributeStringPtr aStringAttr = aData->string(attributeID());
@@ -81,7 +82,7 @@ bool ModuleBase_WidgetFileSelector::storeValueCustom() const
 bool ModuleBase_WidgetFileSelector::restoreValue()
 {
   // A rare case when plugin was not loaded. 
-  if(!myFeature)
+  if (!myFeature)
     return false;
   DataPtr aData = myFeature->data();
   AttributeStringPtr aStringAttr = aData->string(attributeID());
@@ -104,15 +105,16 @@ QList<QWidget*> ModuleBase_WidgetFileSelector::getControls() const
 
 bool ModuleBase_WidgetFileSelector::isCurrentPathValid()
 {
-  QFileInfo aFile (myPathField->text());
+  QFileInfo aFile(myPathField->text());
   return aFile.exists();
 }
 
-
 void ModuleBase_WidgetFileSelector::onPathSelectionBtn()
 {
-  QString aFilter = formatsString();
-  QString aFileName = QFileDialog::getOpenFileName(this, myTitle, myDefaultPath, aFilter);
+  QString aFilter = filterString();
+  QString aFileName = (myType == WFS_SAVE)
+      ? QFileDialog::getSaveFileName(this, myTitle, myDefaultPath, aFilter)
+      : QFileDialog::getOpenFileName(this, myTitle, myDefaultPath, aFilter);
   if (!aFileName.isEmpty()) {
     myPathField->setText(aFileName);
   }
@@ -120,13 +122,13 @@ void ModuleBase_WidgetFileSelector::onPathSelectionBtn()
 
 void ModuleBase_WidgetFileSelector::onPathChanged()
 {
-  if(!isCurrentPathValid())
+  if (myType == WFS_OPEN && !isCurrentPathValid())
     return;
   storeValue();
   emit valuesChanged();
 }
 
-QString ModuleBase_WidgetFileSelector::formatsString() const
+QString ModuleBase_WidgetFileSelector::filterString() const
 {
   QStringList aResult;
   QStringList aValidatorFormats = getValidatorFormats();
@@ -147,21 +149,22 @@ QStringList ModuleBase_WidgetFileSelector::getValidatorFormats() const
   std::list<ModelAPI_Validator*> allValidators;
   std::list<std::list<std::string> > allArguments;
   aFactory->validators(myFeature->getKind(), myAttributeID, allValidators, allArguments);
-  //TODO(sbh): extract as separate method
-  if(allArguments.empty())
-    return QStringList();
+  QStringList aResult;
   std::list<std::string> anArgumentList = allArguments.front();
   std::list<std::string>::const_iterator it = anArgumentList.begin();
-  QStringList aResult;
   for (; it != anArgumentList.end(); ++it) {
-    std::string anArg = *it;
-    int aSepPos = anArg.find(":");
-    if (aSepPos == std::string::npos) {
-      continue;
-    }
-    QString aFormat = QString::fromStdString(anArg.substr(0, aSepPos));
-    aFormat = aFormat.toUpper();
-    aResult.append(aFormat);
+    QString aFormat = getFormat(*it);
+    if (!aFormat.isNull())
+      aResult << aFormat;
   }
   return aResult;
 }
+
+QString ModuleBase_WidgetFileSelector::getFormat( const std::string& theArgument ) const
+{
+  QString anArgument = QString::fromStdString(theArgument);
+  if (!anArgument.contains(":"))
+    return QString();
+  return anArgument.section(":", 0, 0).toUpper();
+}
+
index 744770c61d9087afa07cfcb70cc5dd938a767939..b89531cde6d414665d4aa0b58a6ce3b9efea863c 100644 (file)
@@ -27,6 +27,7 @@ class QLineEdit;
 *  \code
 *      <file_selector
 *          id="import_file_selector"
+*          type="open"
 *          title="Import file"
 *          path="">
 *          <validator id="ExchangePlugin_ImportFormat" parameters="BREP:BREPImport,STEP:STEPImport" />
@@ -68,11 +69,14 @@ protected:
 
  protected:
    /// Returns string containing formats
-  QString formatsString() const;
+  QString filterString() const;
 
-  /// Return list of validator formats
+  /// Returns list of validator formats
   QStringList getValidatorFormats() const;
 
+  /// Returns a format received from theArgument
+  QString getFormat( const std::string& theArgument ) const;
+
  private:
    /// A control for path input
   QLineEdit* myPathField;
@@ -80,6 +84,9 @@ protected:
   /// A title of open file dialog box
   QString myTitle;
 
+  /// A title of open file dialog box
+  enum { WFS_OPEN, WFS_SAVE } myType;
+
   /// Default path
   QString myDefaultPath;
 };