Salome HOME
Implementation of DXFPLUGIN as a GEOM plugin (added files)
[plugins/dxfplugin.git] / src / DXFPlugin_ExportDriver.cxx
1 // Copyright (C) 2014  CEA/DEN, EDF R&D, 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 // internal includes
21 #include "DXFPlugin_ExportDriver.hxx"
22 #include "DXFPlugin_IExport.hxx"
23 #include "DXFPlugin_Engine.hxx"
24
25 // KERNEL includes
26 #include <Basics_Utils.hxx>
27 #include <utilities.h>
28
29 // GEOM includes
30 #include <GEOM_Function.hxx>
31
32 // OOCT includes
33 #include <IFSelect_ReturnStatus.hxx>
34 #include <DxfControl_Writer.hxx>
35 #include <TCollection_AsciiString.hxx>
36 #include <TopoDS_Shape.hxx>
37
38 #ifdef DXF_HASLICENSE
39 #include "DXFPlugin_license.h"
40
41 #include <OCCLicense_Activate.hxx>
42 #include <Standard_LicenseError.hxx>
43 #endif // DXF_HASLICENSE
44
45 //=======================================================================
46 //function : GetID
47 //purpose  :
48 //=======================================================================
49 const Standard_GUID& DXFPlugin_ExportDriver::GetID()
50 {
51   static Standard_GUID aGUID("5bad3191-8af9-4b90-9e95-31f5fdb65304");
52   return aGUID;
53 }
54
55 //=======================================================================
56 //function : DXFPlugin_ExportDriver
57 //purpose  :
58 //=======================================================================
59 DXFPlugin_ExportDriver::DXFPlugin_ExportDriver()
60 {
61 }
62
63 //=======================================================================
64 //function : Execute
65 //purpose  :
66 //=======================================================================
67 Standard_Integer DXFPlugin_ExportDriver::Execute( TFunction_Logbook& log ) const
68 {
69 #ifdef DXF_HASLICENSE
70   try {
71     OCCLicense_Activate("DXF-W-"OCC_VERSION_STRING, DXF_WRITE_LICENSE);
72   }
73   catch (Standard_LicenseError) {
74     return 1;
75   }
76 #endif // DXF_HASLICENSE
77
78   if (Label().IsNull()) return 0;
79   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction( Label() );
80
81   DXFPlugin_IExport aData (aFunction);
82
83   // retrieve the being exported shape
84   TopoDS_Shape aShape;
85   Handle(GEOM_Function) aRefFunction = aData.GetOriginal();
86   if( aRefFunction.IsNull() ) return 0;
87   aShape = aRefFunction->GetValue();
88   if( aShape.IsNull() ) return 0;
89   // set the result of function to be used by next operations
90   aFunction->SetValue( aShape );
91
92   TCollection_AsciiString aFileName = aData.GetFileName();
93
94   MESSAGE("Export DXF into file " << aFileName.ToCString());
95
96   // Set "C" numeric locale to save numbers correctly
97   Kernel_Utils::Localizer loc;
98
99   DxfControl_Writer aWriter;
100
101   IFSelect_ReturnStatus status ;
102   status = aWriter.TransferShape( aShape );
103   if ( status == IFSelect_RetDone )
104         status = aWriter.WriteFile( aFileName.ToCString() ) ;
105   if ( status == IFSelect_RetDone )
106         return 1;
107   else
108     return 0;
109 }
110
111 //=======================================================================
112 //function : MustExecute
113 //purpose  :
114 //=======================================================================
115 Standard_Boolean DXFPlugin_ExportDriver::MustExecute( const TFunction_Logbook& ) const
116 {
117   return Standard_True;
118 }
119
120 //================================================================================
121 /*!
122  * \brief Returns a name of creation operation and names and values of creation parameters
123  */
124 //================================================================================
125 bool DXFPlugin_ExportDriver::
126 GetCreationInformation( std::string&             theOperationName,
127                         std::vector<GEOM_Param>& theParams )
128 {
129   return false;
130 }
131
132 IMPLEMENT_STANDARD_HANDLE( DXFPlugin_ExportDriver,GEOM_BaseDriver );
133 IMPLEMENT_STANDARD_RTTIEXT( DXFPlugin_ExportDriver,GEOM_BaseDriver );