Salome HOME
Implementation of DXFPLUGIN as a GEOM plugin (added files)
[plugins/dxfplugin.git] / src / DXFPlugin_ExportDriver.cxx
index 4727f531535944e4a2dd0ddbc5ae74ce724f78d4..e0275e70deedde707da5f16fafdb778939b8ad27 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014  OPEN CASCADE
+// Copyright (C) 2014  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
-#include <DXFPLUGIN_exports.h>
-#include <DXFPLUGIN_version.h>
+// internal includes
+#include "DXFPlugin_ExportDriver.hxx"
+#include "DXFPlugin_IExport.hxx"
+#include "DXFPlugin_Engine.hxx"
 
+// KERNEL includes
 #include <Basics_Utils.hxx>
+#include <utilities.h>
 
-#include <DxfControl_Writer.hxx>
+// GEOM includes
+#include <GEOM_Function.hxx>
+
+// OOCT includes
 #include <IFSelect_ReturnStatus.hxx>
+#include <DxfControl_Writer.hxx>
 #include <TCollection_AsciiString.hxx>
 #include <TopoDS_Shape.hxx>
 
 #ifdef DXF_HASLICENSE
-#include <DXFPLUGIN_license.h>
+#include "DXFPlugin_license.h"
 
-#include <Standard_LicenseError.hxx>
 #include <OCCLicense_Activate.hxx>
+#include <Standard_LicenseError.hxx>
 #endif // DXF_HASLICENSE
 
-extern "C"
+//=======================================================================
+//function : GetID
+//purpose  :
+//=======================================================================
+const Standard_GUID& DXFPlugin_ExportDriver::GetID()
 {
-  /*!
-    \brief Get version of the plugin.
-    \return the version of the plugin
-  */
-  DXFPLUGIN_EXPORT
-  int GetVersion()
-  {
-    return DXFPLUGIN_VERSION;
-  }
+  static Standard_GUID aGUID("5bad3191-8af9-4b90-9e95-31f5fdb65304");
+  return aGUID;
+}
 
-  /*!
-    \brief Get version of the plugin.
-    \return the string representation of the plugin's version
-  */
-  DXFPLUGIN_EXPORT
-  char* GetVersionStr()
-  {
-    return (char*)DXFPLUGIN_VERSION_STR;
-  }
+//=======================================================================
+//function : DXFPlugin_ExportDriver
+//purpose  :
+//=======================================================================
+DXFPlugin_ExportDriver::DXFPlugin_ExportDriver()
+{
+}
 
-  /*!
-    \brief Export shape to the DXF format.
-    \param theShape shape being exported
-    \param theFileName file path
-    \param theFormatName file format signature
-    \return error status (0 in case of success)
-  */
-  DXFPLUGIN_EXPORT
-  int Export(const TopoDS_Shape& theShape,
-             const TCollection_AsciiString& theFileName,
-             const TCollection_AsciiString& theFormatName)
-  {
+//=======================================================================
+//function : Execute
+//purpose  :
+//=======================================================================
+Standard_Integer DXFPlugin_ExportDriver::Execute( TFunction_Logbook& log ) const
+{
 #ifdef DXF_HASLICENSE
-    try {
-      OCCLicense_Activate("DXF-W-"OCC_VERSION_STRING, DXF_WRITE_LICENSE);
-    } 
-    catch (Standard_LicenseError) {
-      return 1;
-    }
+  try {
+    OCCLicense_Activate("DXF-W-"OCC_VERSION_STRING, DXF_WRITE_LICENSE);
+  }
+  catch (Standard_LicenseError) {
+    return 1;
+  }
 #endif // DXF_HASLICENSE
-    
-    // Set "C" numeric locale to save numbers correctly
-    Kernel_Utils::Localizer loc;
-    
-    DxfControl_Writer aWriter;
-    
-    try {
-      IFSelect_ReturnStatus status ;
-      status = aWriter.TransferShape(theShape);
-      if ( status == IFSelect_RetDone )
-       status = aWriter.WriteFile( theFileName.ToCString() ) ;
-      if ( status == IFSelect_RetDone ) 
+
+  if (Label().IsNull()) return 0;
+  Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction( Label() );
+
+  DXFPlugin_IExport aData (aFunction);
+
+  // retrieve the being exported shape
+  TopoDS_Shape aShape;
+  Handle(GEOM_Function) aRefFunction = aData.GetOriginal();
+  if( aRefFunction.IsNull() ) return 0;
+  aShape = aRefFunction->GetValue();
+  if( aShape.IsNull() ) return 0;
+  // set the result of function to be used by next operations
+  aFunction->SetValue( aShape );
+
+  TCollection_AsciiString aFileName = aData.GetFileName();
+
+  MESSAGE("Export DXF into file " << aFileName.ToCString());
+
+  // Set "C" numeric locale to save numbers correctly
+  Kernel_Utils::Localizer loc;
+
+  DxfControl_Writer aWriter;
+
+  IFSelect_ReturnStatus status ;
+  status = aWriter.TransferShape( aShape );
+  if ( status == IFSelect_RetDone )
+       status = aWriter.WriteFile( aFileName.ToCString() ) ;
+  if ( status == IFSelect_RetDone )
        return 1;
-    }
-    catch(Standard_Failure) {
-      return 1;
-    }
+  else
     return 0;
-  }
-} // end of extern "C"
+}
+
+//=======================================================================
+//function : MustExecute
+//purpose  :
+//=======================================================================
+Standard_Boolean DXFPlugin_ExportDriver::MustExecute( const TFunction_Logbook& ) const
+{
+  return Standard_True;
+}
+
+//================================================================================
+/*!
+ * \brief Returns a name of creation operation and names and values of creation parameters
+ */
+//================================================================================
+bool DXFPlugin_ExportDriver::
+GetCreationInformation( std::string&             theOperationName,
+                        std::vector<GEOM_Param>& theParams )
+{
+  return false;
+}
+
+IMPLEMENT_STANDARD_HANDLE( DXFPlugin_ExportDriver,GEOM_BaseDriver );
+IMPLEMENT_STANDARD_RTTIEXT( DXFPlugin_ExportDriver,GEOM_BaseDriver );