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 "XTPlugin_ImportDriver.hxx"
22 #include "XTPlugin_IImport.hxx"
23 #include "XTPlugin_Engine.hxx"
26 #include <Basics_Utils.hxx>
27 #include <utilities.h>
30 #include <GEOM_Function.hxx>
31 #include <GEOMImpl_Types.hxx>
34 #include <IFSelect_ReturnStatus.hxx>
35 #include <TCollection_AsciiString.hxx>
36 #include <TDF_Label.hxx>
37 #include <TDataStd_Name.hxx>
38 #include <TNaming_Builder.hxx>
39 #include <TopoDS_Shape.hxx>
40 #include <TopoDS_Iterator.hxx>
41 #include <TransferBRep.hxx>
42 #include <Transfer_Binder.hxx>
43 #include <Transfer_TransientProcess.hxx>
44 #include <XtAttributes_AttribGroup.hxx>
45 #include <XtAttributes_Attribute.hxx>
46 #include <XtAttributes_CharValues.hxx>
47 #include <XSControl_TransferReader.hxx>
48 #include <XSControl_WorkSession.hxx>
49 #include <XtControl_Reader.hxx>
50 #include <XtData_HArray1OfObject.hxx>
51 #include <XtData_Model.hxx>
52 #include <XtData_Object.hxx>
53 #include <XtGeom_Curve.hxx>
54 #include <XtGeom_Point.hxx>
55 #include <XtGeom_Surface.hxx>
56 #include <XtTopoDS_Topology.hxx>
58 #include <StdFail_NotDone.hxx>
59 #include <Standard_Version.hxx>
62 #include "XTPlugin_license.h"
64 #include <OCCLicense_Activate.hxx>
65 #include <Standard_LicenseError.hxx>
66 #endif // XT_HASLICENSE
68 //=======================================================================
71 //=======================================================================
72 const Standard_GUID& XTPlugin_ImportDriver::GetID()
74 static Standard_GUID aGUID("81cc16bb-486f-4ec7-87b2-960b4aed557f");
78 //=======================================================================
79 //function : XTPlugin_ImportDriver
81 //=======================================================================
82 XTPlugin_ImportDriver::XTPlugin_ImportDriver()
86 //=======================================================================
89 //=======================================================================
90 Standard_Integer XTPlugin_ImportDriver::Execute( TFunction_Logbook& log ) const
92 if( Label().IsNull() ) return 0;
93 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction( Label() );
95 XTPlugin_IImport aData( aFunction );
97 TCollection_AsciiString aFileName = aData.GetFileName().ToCString();
99 MESSAGE("Import XT from file " << aFileName);
101 TopoDS_Shape aResShape;
105 OCCLicense_Activate( "XT-R-"OCC_VERSION_STRING, XT_READ_LICENSE);
107 catch (Standard_LicenseError) {
110 #endif // XT_HASLICENSE
112 // Set "C" numeric locale to save numbers correctly
113 Kernel_Utils::Localizer loc;
115 XtControl_Reader aReader;
117 IFSelect_ReturnStatus status = aReader.ReadFile(aFileName.ToCString());
118 if (status == IFSelect_RetDone) {
119 aReader.TransferRoots();
120 aResShape = aReader.OneShape();
122 // ATTENTION: this is a workaround for mantis issue 0020442 remark 0010776
123 // It should be removed after patching OCCT for bug OCC22436
124 // (fix for OCCT is expected in service pack next to OCCT6.3sp12)
125 if (aResShape.ShapeType() == TopAbs_COMPOUND) {
127 TopoDS_Shape currShape;
128 TopoDS_Iterator It (aResShape, Standard_True, Standard_True);
129 for (; It.More(); It.Next()) {
131 currShape = It.Value();
134 aResShape = currShape;
136 Handle(XtData_Model) aModel = Handle(XtData_Model)::DownCast( aReader.WS()->Model() );
137 Handle(XSControl_TransferReader) TR = aReader.WS()->TransferReader();
139 Handle(Transfer_TransientProcess) TP = TR->TransientProcess();
140 Standard_Integer nb = aModel->NbEntities();
141 for (Standard_Integer i = 1; i <= nb; i ++) {
142 Handle(XtData_Object) XtOb = Handle(XtData_Object)::DownCast ( aModel->Value(i) );
143 if (XtOb.IsNull()) continue;
145 Handle(XtAttributes_AttribGroup) XtAG;
146 Standard_Boolean MayBeName = Standard_False;
148 if (XtOb->IsKind(STANDARD_TYPE(XtTopoDS_Topology))) {
149 Handle(XtTopoDS_Topology) XtT = Handle(XtTopoDS_Topology)::DownCast(XtOb);
150 XtAG = XtT->AttributesGroups();
151 MayBeName = Standard_True;
153 else if (XtOb->IsKind(STANDARD_TYPE(XtGeom_Surface))) {
154 Handle(XtGeom_Surface) XtGS = Handle(XtGeom_Surface)::DownCast(XtOb);
155 XtAG = XtGS->AttributesGroups();
156 MayBeName = Standard_True;
158 else if (XtOb->IsKind(STANDARD_TYPE(XtGeom_Curve))) {
159 Handle(XtGeom_Curve) XtGC = Handle(XtGeom_Curve)::DownCast(XtOb);
160 XtAG = XtGC->AttributesGroups();
161 MayBeName = Standard_True;
163 else if (XtOb->IsKind(STANDARD_TYPE(XtGeom_Point))) {
164 Handle(XtGeom_Point) XtGP = Handle(XtGeom_Point)::DownCast(XtOb);
165 XtAG = XtGP->AttributesGroups();
166 MayBeName = Standard_True;
170 TCollection_AsciiString string;
171 Standard_Boolean IsName = Standard_False;
172 Handle(XtAttributes_Attribute) XtA = Handle(XtAttributes_Attribute)::DownCast(XtAG);
174 Handle(XtAttributes_AttribDef) XtAD = XtA->Definition();
175 while (!XtAD.IsNull()) {
176 if (XtAD->TypeID()==8017) {
177 const Handle(XtData_HArray1OfObject) &HAFV = XtA->Fields();
178 const Standard_Integer NbFV = HAFV->Length();
179 for (Standard_Integer j=1; j<=NbFV; j++) {
180 const Handle(XtData_Object) &FV = HAFV->Value(j);
181 if(!FV.IsNull() && FV->IsKind(STANDARD_TYPE(XtAttributes_CharValues))) {
182 string = Handle(XtAttributes_CharValues)::DownCast(FV)->Values();
183 IsName = Standard_True;
192 Handle(Transfer_Binder) binder = TP->Find ( XtOb );
193 if ( binder.IsNull() ) continue;
194 TopoDS_Shape S = TransferBRep::ShapeResult (binder);
195 if ( S.IsNull() ) continue;
199 L = aTag.NewChild(aFunction->GetNamingEntry());
200 TNaming_Builder tnBuild(L);
201 tnBuild.Generated(S);
203 // set a name to the document
205 string.RightAdjust();
206 TCollection_ExtendedString str ( string );
207 TDataStd_Name::Set ( L, str );
214 TCollection_AsciiString anError = "Wrong format of the imported file. Can't import file.";
215 StdFail_NotDone::Raise( anError.ToCString() );
219 if( aResShape.IsNull() ) return 0;
221 aFunction->SetValue( aResShape );
223 log.SetTouched( Label() );
228 //=======================================================================
229 //function : MustExecute
231 //=======================================================================
232 Standard_Boolean XTPlugin_ImportDriver::MustExecute( const TFunction_Logbook& ) const
234 return Standard_True;
237 //================================================================================
239 * \brief Returns a name of creation operation and names and values of creation parameters
241 //================================================================================
243 bool XTPlugin_ImportDriver::
244 GetCreationInformation( std::string& theOperationName,
245 std::vector<GEOM_Param>& theParams )
247 if( Label().IsNull() ) return 0;
248 Handle(GEOM_Function) function = GEOM_Function::GetFunction( Label() );
250 XTPlugin_IImport aCI( function );
251 Standard_Integer aType = function->GetType();
253 theOperationName = "ImportXT";
257 AddParam( theParams, "File name", aCI.GetFileName() );
265 IMPLEMENT_STANDARD_HANDLE( XTPlugin_ImportDriver, GEOM_BaseDriver );
266 IMPLEMENT_STANDARD_RTTIEXT( XTPlugin_ImportDriver, GEOM_BaseDriver );