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