1 // Copyright (C) 2014-2016 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>
50 #include <Standard_Version.hxx>
52 #ifdef ACIS_HASLICENSE
53 #include "ACISPlugin_license.h"
55 #include <OCCLicense_Activate.hxx>
56 #include <Standard_LicenseError.hxx>
57 #endif // ACIS_HASLICENSE
59 //=======================================================================
62 //=======================================================================
63 const Standard_GUID& ACISPlugin_ImportDriver::GetID()
65 static Standard_GUID aGUID("4e2fea67-84bc-44fe-9a32-ac52a246154c");
69 //=======================================================================
70 //function : ACISPlugin_ImportDriver
72 //=======================================================================
73 ACISPlugin_ImportDriver::ACISPlugin_ImportDriver()
77 //=======================================================================
80 //=======================================================================
81 Standard_Integer ACISPlugin_ImportDriver::Execute( Handle(TFunction_Logbook)& log ) const
83 if( Label().IsNull() ) return 0;
84 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction( Label() );
86 ACISPlugin_IImport aData( aFunction );
88 TCollection_AsciiString aFileName = aData.GetFileName().ToCString();
90 MESSAGE("Import ACIS from file " << aFileName);
91 TopoDS_Shape aResShape;
93 #ifdef ACIS_HASLICENSE
95 OCCLicense_Activate( "SAT-R-"OCC_VERSION_STRING, ACIS_READ_LICENSE);
97 catch (Standard_LicenseError) {
100 #endif // ACIS_HASLICENSE
102 // Set "C" numeric locale to save numbers correctly
103 Kernel_Utils::Localizer loc;
105 SatControl_Reader aReader;
107 IFSelect_ReturnStatus status = aReader.ReadFile( aFileName.ToCString() );
108 if (status == IFSelect_RetDone) {
109 aReader.TransferRoots();
110 aResShape = aReader.OneShape();
111 Handle(Interface_InterfaceModel) Model = aReader.WS()->Model();
112 Handle(XSControl_TransferReader) TR = aReader.WS()->TransferReader();
114 Handle(Transfer_TransientProcess) TP = TR->TransientProcess();
115 Standard_Integer nb = Model->NbEntities();
116 for (Standard_Integer i = 1; i <= nb; i ++) {
117 Handle(AcisEnt_Attrib) attr = Handle(AcisEnt_Attrib)::DownCast ( Model->Value(i) );
118 if ( attr.IsNull() ) continue; //not only Entity Label (f.18) but Name Property also
120 TCollection_AsciiString aName;
121 if( attr->IsKind(STANDARD_TYPE(AcisAttr_AttribGenName)) ) {
122 Handle(AcisAttr_AttribGenName) attrname = Handle(AcisAttr_AttribGenName)::DownCast ( attr );
123 aName = attrname->myNameAttr;
125 else continue; // no name assigned
127 // find target entity
128 Handle(AcisEnt_Entity) ent;
130 ent = attr->myEntity;
131 attr = Handle(AcisEnt_Attrib)::DownCast ( ent );
132 } while ( ! attr.IsNull() );
133 if ( ent.IsNull() ) continue; // strange - no normal entity found ?
136 Handle(Transfer_Binder) binder = TP->Find ( ent );
137 if( binder.IsNull() ) continue;
138 TopoDS_Shape S = TransferBRep::ShapeResult (binder);
139 if( S.IsNull() ) continue;
141 // create label and set shape
144 L = aTag.NewChild(aFunction->GetNamingEntry());
145 TNaming_Builder tnBuild(L);
146 tnBuild.Generated(S);
149 TCollection_ExtendedString str(aName);
150 TDataStd_Name::Set(L,str);
155 TCollection_AsciiString anError = "Wrong format of the imported file. Can't import file.";
156 StdFail_NotDone::Raise( anError.ToCString() );
160 if( aResShape.IsNull() ) return 0;
162 aFunction->SetValue( aResShape );
164 log->SetTouched(Label());
169 //================================================================================
171 * \brief Returns a name of creation operation and names and values of creation parameters
173 //================================================================================
175 bool ACISPlugin_ImportDriver::
176 GetCreationInformation( std::string& theOperationName,
177 std::vector<GEOM_Param>& theParams )
179 if( Label().IsNull() ) return 0;
180 Handle(GEOM_Function) function = GEOM_Function::GetFunction( Label() );
182 ACISPlugin_IImport aCI( function );
183 Standard_Integer aType = function->GetType();
185 theOperationName = "ImportACIS";
189 AddParam( theParams, "File name", aCI.GetFileName() );
197 IMPLEMENT_STANDARD_RTTIEXT( ACISPlugin_ImportDriver, GEOM_BaseDriver );