1 // Copyright (C) 2014 CEA/DEN, EDF R&D, 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>
61 #include "XTPlugin_license.h"
63 #include <OCCLicense_Activate.hxx>
64 #include <Standard_LicenseError.hxx>
65 #endif // XT_HASLICENSE
67 //=======================================================================
70 //=======================================================================
71 const Standard_GUID& XTPlugin_ImportDriver::GetID()
73 static Standard_GUID aGUID("81cc16bb-486f-4ec7-87b2-960b4aed557f");
77 //=======================================================================
78 //function : XTPlugin_ImportDriver
80 //=======================================================================
81 XTPlugin_ImportDriver::XTPlugin_ImportDriver()
85 //=======================================================================
88 //=======================================================================
89 Standard_Integer XTPlugin_ImportDriver::Execute( TFunction_Logbook& log ) const
91 if( Label().IsNull() ) return 0;
92 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction( Label() );
94 XTPlugin_IImport aData( aFunction );
96 TCollection_AsciiString aFileName = aData.GetFileName().ToCString();
98 MESSAGE("Import XT from file " << aFileName);
100 TopoDS_Shape aResShape;
104 OCCLicense_Activate( "XT-R-"OCC_VERSION_STRING, XT_READ_LICENSE);
106 catch (Standard_LicenseError) {
109 #endif // XT_HASLICENSE
111 // Set "C" numeric locale to save numbers correctly
112 Kernel_Utils::Localizer loc;
114 XtControl_Reader aReader;
116 IFSelect_ReturnStatus status = aReader.ReadFile(aFileName.ToCString());
117 if (status == IFSelect_RetDone) {
118 aReader.TransferRoots();
119 aResShape = aReader.OneShape();
121 // ATTENTION: this is a workaround for mantis issue 0020442 remark 0010776
122 // It should be removed after patching OCCT for bug OCC22436
123 // (fix for OCCT is expected in service pack next to OCCT6.3sp12)
124 if (aResShape.ShapeType() == TopAbs_COMPOUND) {
126 TopoDS_Shape currShape;
127 TopoDS_Iterator It (aResShape, Standard_True, Standard_True);
128 for (; It.More(); It.Next()) {
130 currShape = It.Value();
133 aResShape = currShape;
135 Handle(XtData_Model) aModel = Handle(XtData_Model)::DownCast( aReader.WS()->Model() );
136 Handle(XSControl_TransferReader) TR = aReader.WS()->TransferReader();
138 Handle(Transfer_TransientProcess) TP = TR->TransientProcess();
139 Standard_Integer nb = aModel->NbEntities();
140 for (Standard_Integer i = 1; i <= nb; i ++) {
141 Handle(XtData_Object) XtOb = Handle(XtData_Object)::DownCast ( aModel->Value(i) );
142 if (XtOb.IsNull()) continue;
144 Handle(XtAttributes_AttribGroup) XtAG;
145 Standard_Boolean MayBeName = Standard_False;
147 if (XtOb->IsKind(STANDARD_TYPE(XtTopoDS_Topology))) {
148 Handle(XtTopoDS_Topology) XtT = Handle(XtTopoDS_Topology)::DownCast(XtOb);
149 XtAG = XtT->AttributesGroups();
150 MayBeName = Standard_True;
152 else if (XtOb->IsKind(STANDARD_TYPE(XtGeom_Surface))) {
153 Handle(XtGeom_Surface) XtGS = Handle(XtGeom_Surface)::DownCast(XtOb);
154 XtAG = XtGS->AttributesGroups();
155 MayBeName = Standard_True;
157 else if (XtOb->IsKind(STANDARD_TYPE(XtGeom_Curve))) {
158 Handle(XtGeom_Curve) XtGC = Handle(XtGeom_Curve)::DownCast(XtOb);
159 XtAG = XtGC->AttributesGroups();
160 MayBeName = Standard_True;
162 else if (XtOb->IsKind(STANDARD_TYPE(XtGeom_Point))) {
163 Handle(XtGeom_Point) XtGP = Handle(XtGeom_Point)::DownCast(XtOb);
164 XtAG = XtGP->AttributesGroups();
165 MayBeName = Standard_True;
169 TCollection_AsciiString string;
170 Standard_Boolean IsName = Standard_False;
171 Handle(XtAttributes_Attribute) XtA = Handle(XtAttributes_Attribute)::DownCast(XtAG);
173 Handle(XtAttributes_AttribDef) XtAD = XtA->Definition();
174 while (!XtAD.IsNull()) {
175 if (XtAD->TypeID()==8017) {
176 const Handle(XtData_HArray1OfObject) &HAFV = XtA->Fields();
177 const Standard_Integer NbFV = HAFV->Length();
178 for (Standard_Integer j=1; j<=NbFV; j++) {
179 const Handle(XtData_Object) &FV = HAFV->Value(j);
180 if(!FV.IsNull() && FV->IsKind(STANDARD_TYPE(XtAttributes_CharValues))) {
181 string = Handle(XtAttributes_CharValues)::DownCast(FV)->Values();
182 IsName = Standard_True;
191 Handle(Transfer_Binder) binder = TP->Find ( XtOb );
192 if ( binder.IsNull() ) continue;
193 TopoDS_Shape S = TransferBRep::ShapeResult (binder);
194 if ( S.IsNull() ) continue;
198 L = aTag.NewChild(aFunction->GetNamingEntry());
199 TNaming_Builder tnBuild(L);
200 tnBuild.Generated(S);
202 // set a name to the document
204 string.RightAdjust();
205 TCollection_ExtendedString str ( string );
206 TDataStd_Name::Set ( L, str );
213 TCollection_AsciiString anError = "Wrong format of the imported file. Can't import file.";
214 StdFail_NotDone::Raise( anError.ToCString() );
218 if( aResShape.IsNull() ) return 0;
220 aFunction->SetValue( aResShape );
222 log.SetTouched( Label() );
227 //=======================================================================
228 //function : MustExecute
230 //=======================================================================
231 Standard_Boolean XTPlugin_ImportDriver::MustExecute( const TFunction_Logbook& ) const
233 return Standard_True;
236 //================================================================================
238 * \brief Returns a name of creation operation and names and values of creation parameters
240 //================================================================================
242 bool XTPlugin_ImportDriver::
243 GetCreationInformation( std::string& theOperationName,
244 std::vector<GEOM_Param>& theParams )
246 if( Label().IsNull() ) return 0;
247 Handle(GEOM_Function) function = GEOM_Function::GetFunction( Label() );
249 XTPlugin_IImport aCI( function );
250 Standard_Integer aType = function->GetType();
252 theOperationName = "ImportXT";
256 AddParam( theParams, "File name", aCI.GetFileName() );
264 IMPLEMENT_STANDARD_HANDLE( XTPlugin_ImportDriver, GEOM_BaseDriver );
265 IMPLEMENT_STANDARD_RTTIEXT( XTPlugin_ImportDriver, GEOM_BaseDriver );