1 // Copyright (C) 2014 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
20 #include <ACISPLUGIN_exports.h>
21 #include <ACISPLUGIN_version.h>
23 #include <Basics_Utils.hxx>
25 #include <AcisAttr_AttribGenName.hxx>
26 #include <AcisEnt_Attrib.hxx>
27 #include <IFSelect_ReturnStatus.hxx>
28 #include <Interface_InterfaceModel.hxx>
29 #include <SatControl_Reader.hxx>
30 #include <TCollection_AsciiString.hxx>
31 #include <TDataStd_Name.hxx>
32 #include <TDF_Label.hxx>
33 #include <TNaming_Builder.hxx>
34 #include <TopoDS_Shape.hxx>
35 #include <TransferBRep.hxx>
36 #include <Transfer_Binder.hxx>
37 #include <Transfer_TransientProcess.hxx>
38 #include <XSControl_TransferReader.hxx>
39 #include <XSControl_WorkSession.hxx>
41 #ifdef ACIS_HASLICENSE
42 #include <ACISPLUGIN_license.h>
44 #include <OCCLicense_Activate.hxx>
45 #include <Standard_LicenseError.hxx>
46 #endif // ACIS_HASLICENSE
51 \brief Get version of the plugin.
52 \return the version of the plugin
57 return ACISPLUGIN_VERSION;
61 \brief Get version of the plugin.
62 \return the string representation of the plugin's version
67 return (char*)ACISPLUGIN_VERSION_STR;
71 \brief Import shape from the ACIS format.
72 \param theFileName file path
73 \param theFormatName file format signature
74 \param theError error description, if there's any, is returned via this parameter
75 \param theShapeLabel a label in the CAF tree where shape attributes are set to
76 \return imported shape
79 TopoDS_Shape Import(const TCollection_AsciiString& theFileName,
80 const TCollection_AsciiString& /*theFormatName*/,
81 TCollection_AsciiString& theError,
82 const TDF_Label& theShapeLabel)
84 TopoDS_Shape aResShape;
86 #ifdef ACIS_HASLICENSE
88 OCCLicense_Activate( "SAT-R-"OCC_VERSION_STRING, ACIS_READ_LICENSE);
90 catch (Standard_LicenseError) {
93 #endif // ACIS_HASLICENSE
95 // Set "C" numeric locale to save numbers correctly
96 Kernel_Utils::Localizer loc;
98 SatControl_Reader aReader;
101 IFSelect_ReturnStatus status = aReader.ReadFile(theFileName.ToCString());
102 if (status == IFSelect_RetDone) {
103 aReader.TransferRoots();
104 aResShape = aReader.OneShape();
105 Handle(Interface_InterfaceModel) Model = aReader.WS()->Model();
106 Handle(XSControl_TransferReader) TR = aReader.WS()->TransferReader();
108 Handle(Transfer_TransientProcess) TP = TR->TransientProcess();
109 Standard_Integer nb = Model->NbEntities();
110 for (Standard_Integer i = 1; i <= nb; i ++) {
111 Handle(AcisEnt_Attrib) attr = Handle(AcisEnt_Attrib)::DownCast ( Model->Value(i) );
112 if ( attr.IsNull() ) continue; //not only Entity Label (f.18) but Name Property also
114 TCollection_AsciiString aName;
115 if ( attr->IsKind(STANDARD_TYPE(AcisAttr_AttribGenName)) ) {
116 Handle(AcisAttr_AttribGenName) attrname = Handle(AcisAttr_AttribGenName)::DownCast ( attr );
117 aName = attrname->myNameAttr;
119 else continue; // no name assigned
121 // find target entity
122 Handle(AcisEnt_Entity) ent;
124 ent = attr->myEntity;
125 attr = Handle(AcisEnt_Attrib)::DownCast ( ent );
126 } while ( ! attr.IsNull() );
127 if ( ent.IsNull() ) continue; // strange - no normal entity found ?
130 Handle(Transfer_Binder) binder = TP->Find ( ent );
131 if ( binder.IsNull() ) continue;
132 TopoDS_Shape S = TransferBRep::ShapeResult (binder);
133 if ( S.IsNull() ) continue;
135 //if( S.IsEqual(aResShape) ) continue;
137 // create label and set shape
140 L = aTag.NewChild(theShapeLabel);
141 TNaming_Builder tnBuild(L);
142 tnBuild.Generated(S);
145 TCollection_ExtendedString str(aName);
146 TDataStd_Name::Set(L,str);
151 theError = "Wrong format of the imported file. Can't import file.";
155 catch (Standard_Failure) {
156 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
157 theError = aFail->GetMessageString();
162 } // end of extern "C"