1 // Copyright (C) 2014-2015 OPEN CASCADE
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #include "ACISPlugin_ImportDriver.hxx"
22 #include "ACISPlugin_IImport.hxx"
25 #include <Basics_Utils.hxx>
26 #include <utilities.h>
29 #include <GEOM_Function.hxx>
30 #include <GEOMImpl_Types.hxx>
33 #include <AcisAttr_AttribGenName.hxx>
34 #include <AcisEnt_Attrib.hxx>
35 #include <IFSelect_ReturnStatus.hxx>
36 #include <Interface_InterfaceModel.hxx>
37 #include <SatControl_Reader.hxx>
38 #include <TCollection_AsciiString.hxx>
39 #include <TDataStd_Name.hxx>
40 #include <TDF_Label.hxx>
41 #include <TNaming_Builder.hxx>
42 #include <TopoDS_Shape.hxx>
43 #include <TransferBRep.hxx>
44 #include <Transfer_Binder.hxx>
45 #include <Transfer_TransientProcess.hxx>
46 #include <XSControl_TransferReader.hxx>
47 #include <XSControl_WorkSession.hxx>
49 #include <StdFail_NotDone.hxx>
51 #ifdef ACIS_HASLICENSE
52 #include "ACISPlugin_license.h"
54 #include <OCCLicense_Activate.hxx>
55 #include <Standard_LicenseError.hxx>
56 #endif // ACIS_HASLICENSE
58 //=======================================================================
61 //=======================================================================
62 const Standard_GUID& ACISPlugin_ImportDriver::GetID()
64 static Standard_GUID aGUID("4e2fea67-84bc-44fe-9a32-ac52a246154c");
68 //=======================================================================
69 //function : ACISPlugin_ImportDriver
71 //=======================================================================
72 ACISPlugin_ImportDriver::ACISPlugin_ImportDriver()
76 //=======================================================================
79 //=======================================================================
80 Standard_Integer ACISPlugin_ImportDriver::Execute( TFunction_Logbook& log ) const
82 if( Label().IsNull() ) return 0;
83 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction( Label() );
85 ACISPlugin_IImport aData( aFunction );
87 TCollection_AsciiString aFileName = aData.GetFileName().ToCString();
89 MESSAGE("Import ACIS from file " << aFileName);
90 TopoDS_Shape aResShape;
92 #ifdef ACIS_HASLICENSE
94 OCCLicense_Activate( "SAT-R-"OCC_VERSION_STRING, ACIS_READ_LICENSE);
96 catch (Standard_LicenseError) {
99 #endif // ACIS_HASLICENSE
101 // Set "C" numeric locale to save numbers correctly
102 Kernel_Utils::Localizer loc;
104 SatControl_Reader aReader;
106 IFSelect_ReturnStatus status = aReader.ReadFile( aFileName.ToCString() );
107 if (status == IFSelect_RetDone) {
108 aReader.TransferRoots();
109 aResShape = aReader.OneShape();
110 Handle(Interface_InterfaceModel) Model = aReader.WS()->Model();
111 Handle(XSControl_TransferReader) TR = aReader.WS()->TransferReader();
113 Handle(Transfer_TransientProcess) TP = TR->TransientProcess();
114 Standard_Integer nb = Model->NbEntities();
115 for (Standard_Integer i = 1; i <= nb; i ++) {
116 Handle(AcisEnt_Attrib) attr = Handle(AcisEnt_Attrib)::DownCast ( Model->Value(i) );
117 if ( attr.IsNull() ) continue; //not only Entity Label (f.18) but Name Property also
119 TCollection_AsciiString aName;
120 if( attr->IsKind(STANDARD_TYPE(AcisAttr_AttribGenName)) ) {
121 Handle(AcisAttr_AttribGenName) attrname = Handle(AcisAttr_AttribGenName)::DownCast ( attr );
122 aName = attrname->myNameAttr;
124 else continue; // no name assigned
126 // find target entity
127 Handle(AcisEnt_Entity) ent;
129 ent = attr->myEntity;
130 attr = Handle(AcisEnt_Attrib)::DownCast ( ent );
131 } while ( ! attr.IsNull() );
132 if ( ent.IsNull() ) continue; // strange - no normal entity found ?
135 Handle(Transfer_Binder) binder = TP->Find ( ent );
136 if( binder.IsNull() ) continue;
137 TopoDS_Shape S = TransferBRep::ShapeResult (binder);
138 if( S.IsNull() ) continue;
140 // create label and set shape
143 L = aTag.NewChild(aFunction->GetNamingEntry());
144 TNaming_Builder tnBuild(L);
145 tnBuild.Generated(S);
148 TCollection_ExtendedString str(aName);
149 TDataStd_Name::Set(L,str);
154 TCollection_AsciiString anError = "Wrong format of the imported file. Can't import file.";
155 StdFail_NotDone::Raise( anError.ToCString() );
159 if( aResShape.IsNull() ) return 0;
161 aFunction->SetValue( aResShape );
163 log.SetTouched( Label() );
168 //=======================================================================
169 //function : MustExecute
171 //=======================================================================
172 Standard_Boolean ACISPlugin_ImportDriver::MustExecute( const TFunction_Logbook& ) const
174 return Standard_True;
177 //================================================================================
179 * \brief Returns a name of creation operation and names and values of creation parameters
181 //================================================================================
183 bool ACISPlugin_ImportDriver::
184 GetCreationInformation( std::string& theOperationName,
185 std::vector<GEOM_Param>& theParams )
187 if( Label().IsNull() ) return 0;
188 Handle(GEOM_Function) function = GEOM_Function::GetFunction( Label() );
190 ACISPlugin_IImport aCI( function );
191 Standard_Integer aType = function->GetType();
193 theOperationName = "ImportACIS";
197 AddParam( theParams, "File name", aCI.GetFileName() );
205 IMPLEMENT_STANDARD_HANDLE( ACISPlugin_ImportDriver, GEOM_BaseDriver );
206 IMPLEMENT_STANDARD_RTTIEXT( ACISPlugin_ImportDriver, GEOM_BaseDriver );