Salome HOME
Copyrights update 2015.
[plugins/acisplugin.git] / src / ACISExport / ACISExport.cxx
1 // Copyright (C) 2014-2015  OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include <ACISPLUGIN_exports.h>
21 #include <ACISPLUGIN_version.h>
22
23 #include <Basics_Utils.hxx>
24
25 #include <IFSelect_ReturnStatus.hxx>
26 #include <SatControl_Writer.hxx>
27 #include <TCollection_AsciiString.hxx>
28 #include <TopoDS_Shape.hxx>
29
30 #ifdef ACIS_HASLICENSE
31 #include <ACISPLUGIN_license.h>
32
33 #include <OCCLicense_Activate.hxx>
34 #include <Standard_LicenseError.hxx>
35 #endif // ACIS_HASLICENSE
36
37 extern "C"
38 {
39   /*!
40     \brief Get version of the plugin.
41     \return the version of the plugin
42   */
43   ACISPLUGIN_EXPORT
44   int GetVersion()
45   {
46     return ACISPLUGIN_VERSION;
47   }
48
49   /*!
50     \brief Get version of the plugin.
51     \return the string representation of the plugin's version
52   */
53   ACISPLUGIN_EXPORT
54   char* GetVersionStr()
55   {
56     return (char*)ACISPLUGIN_VERSION_STR;
57   }
58
59   /*!
60     \brief Export shape to the ACIS format.
61     \param theShape shape being exported
62     \param theFileName file path
63     \param theFormatName file format signature
64     \return error status (0 in case of success)
65   */
66   ACISPLUGIN_EXPORT
67   int Export(const TopoDS_Shape& theShape,
68              const TCollection_AsciiString& theFileName,
69              const TCollection_AsciiString& theFormatName)
70   {
71 #ifdef ACIS_HASLICENSE
72     try {
73       OCCLicense_Activate("SAT-W-"OCC_VERSION_STRING, ACIS_WRITE_LICENSE);
74     }
75     catch (Standard_LicenseError) {
76       return 1;
77     }
78 #endif // ACIS_HASLICENSE
79     
80     // Set "C" numeric locale to save numbers correctly
81     Kernel_Utils::Localizer loc;
82     
83     SatControl_Writer aWriter;
84     
85     try {
86       IFSelect_ReturnStatus status ;
87       status = aWriter.TransferShape(theShape);
88       if ( status == IFSelect_RetDone )
89         status = aWriter.WriteFile( theFileName.ToCString() ) ;
90       if ( status == IFSelect_RetDone )
91         return 1;
92     }
93     catch(Standard_Failure) {
94       return 1;
95     }
96     return 0;
97   }
98 } // end of extern "C"