Salome HOME
Implementation of DXFPLUGIN as a GEOM plugin (added files)
[plugins/dxfplugin.git] / src / DXFPlugin_Operations_i.cc
diff --git a/src/DXFPlugin_Operations_i.cc b/src/DXFPlugin_Operations_i.cc
new file mode 100644 (file)
index 0000000..115daf0
--- /dev/null
@@ -0,0 +1,134 @@
+// 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
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+// internal includes
+#include "DXFPlugin_Operations_i.hh"
+#include <DXFPLUGIN_version.h>
+
+// KERNEL includes
+#include <utilities.h>
+
+//=============================================================================
+/*!
+ *   constructor:
+ */
+//=============================================================================
+DXFPlugin_Operations_i::DXFPlugin_Operations_i( PortableServer::POA_ptr thePOA,
+                                                            GEOM::GEOM_Gen_ptr theEngine,
+                                                            ::DXFPlugin_IOperations* theImpl )
+:GEOM_IOperations_i( thePOA, theEngine, theImpl )
+{
+  MESSAGE( "DXFPlugin_Operations_i::DXFPlugin_Operations_i" );
+}
+
+//=============================================================================
+/*!
+ *  destructor
+ */
+//=============================================================================
+DXFPlugin_Operations_i::~DXFPlugin_Operations_i()
+{
+  MESSAGE( "DXFPlugin_Operations_i::~DXFPlugin_Operations_i" );
+}
+
+//=============================================================================
+/*!
+ *  ExportDXF
+ *  Export a shape to DXF format
+ *  \param theOriginal The shape to export
+ *  \param theFileName The name of the exported file
+ */
+//=============================================================================
+void DXFPlugin_Operations_i::ExportDXF( GEOM::GEOM_Object_ptr theOriginal,
+                                               const char*           theFileName )
+{
+  // duplicate the original shape
+  GEOM::GEOM_Object_var aGEOMObject = GEOM::GEOM_Object::_duplicate( theOriginal );
+
+  //Set a not done flag
+  GetOperations()->SetNotDone();
+
+  //Get the reference shape
+  Handle(GEOM_Object) anOriginal = GetObjectImpl( theOriginal );
+  if (anOriginal.IsNull()) return;
+
+  //Export the shape to the file
+  char* aFileName = strdup( theFileName );
+
+  GetOperations()->ExportDXF( anOriginal, aFileName );
+  free( aFileName );
+}
+
+//=============================================================================
+/*!
+ *  ImportDXF
+ *  Import a shape from DXF format
+ *  \param theFileName The name of the file to import
+ *  \return List of GEOM_Objects, containing the created shape and propagation groups.
+ */
+//=============================================================================
+GEOM::ListOfGO* DXFPlugin_Operations_i::ImportDXF( const char* theFileName )
+{
+  GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
+
+  //Set a not done flag
+  GetOperations()->SetNotDone();
+
+  //Import the shape from the file
+  char* aFileName = strdup( theFileName );
+  TCollection_AsciiString fileName( aFileName );
+
+  //Import the shape from the file
+  Handle(TColStd_HSequenceOfTransient) aHSeq = GetOperations()->ImportDXF( fileName );
+
+  free( aFileName );
+  if( !GetOperations()->IsDone() || aHSeq.IsNull() )
+    return aSeq._retn();
+
+  // Copy created objects.
+  Standard_Integer aLength = aHSeq->Length();
+  aSeq->length( aLength );
+  for( Standard_Integer i = 1; i <= aLength; i++ )
+    aSeq[i-1] = GetObject( Handle(GEOM_Object)::DownCast( aHSeq->Value(i) ) );
+
+  return aSeq._retn();
+}
+
+//=============================================================================
+/*!
+ *  \brief Get version of the plugin.
+ *  \return the version of the plugin
+*/
+//=============================================================================
+
+int DXFPlugin_Operations_i::GetVersion()
+{
+  return DXFPLUGIN_VERSION;
+}
+//=============================================================================
+/*!
+ *  \brief Get version of the plugin.
+ *  \return the string representation of the plugin's version
+*/
+//=============================================================================
+
+char* DXFPlugin_Operations_i::GetVersionStr()
+{
+  return (char*)DXFPLUGIN_VERSION_STR;
+}