1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
4 * ExchangePlugin_ImportFeature.cpp
6 * Created on: Aug 28, 2014
10 #include <ExchangePlugin_ImportFeature.h>
11 #include <GeomAlgoAPI_BREPImport.h>
12 #include <GeomAlgoAPI_STEPImport.h>
13 #include <GeomAlgoAPI_IGESImport.h>
15 #include <GeomAPI_Shape.h>
16 #include <Config_Common.h>
17 #include <Config_PropManager.h>
19 #include <ModelAPI_AttributeString.h>
20 #include <ModelAPI_Data.h>
21 #include <ModelAPI_Document.h>
22 #include <ModelAPI_Object.h>
23 #include <ModelAPI_ResultBody.h>
24 #include <TCollection_AsciiString.hxx>
25 #include <TDF_Label.hxx>
26 #include <TopoDS_Shape.hxx>
27 #include <OSD_Path.hxx>
36 ExchangePlugin_ImportFeature::ExchangePlugin_ImportFeature()
40 ExchangePlugin_ImportFeature::~ExchangePlugin_ImportFeature()
42 // TODO Auto-generated destructor stub
46 * Returns the unique kind of a feature
48 const std::string& ExchangePlugin_ImportFeature::getKind()
50 return ExchangePlugin_ImportFeature::ID();
54 * Request for initialization of data model of the feature: adding all attributes
56 void ExchangePlugin_ImportFeature::initAttributes()
58 data()->addAttribute(ExchangePlugin_ImportFeature::FILE_PATH_ID(), ModelAPI_AttributeString::typeId());
62 * Computes or recomputes the results
64 void ExchangePlugin_ImportFeature::execute()
66 AttributeStringPtr aFilePathAttr = std::dynamic_pointer_cast<ModelAPI_AttributeString>(
67 data()->attribute(ExchangePlugin_ImportFeature::FILE_PATH_ID()));
68 std::string aFilePath = aFilePathAttr->value();
71 importFile(aFilePath);
74 bool ExchangePlugin_ImportFeature::importFile(const std::string& theFileName)
76 // retrieve the file and plugin library names
77 TCollection_AsciiString aFileName (theFileName.c_str());
78 OSD_Path aPath(aFileName);
79 TCollection_AsciiString aFormatName = aPath.Extension();
80 // ".brep" -> "BREP", TCollection_AsciiString are numbered from 1
81 aFormatName = aFormatName.SubString(2, aFormatName.Length());
82 aFormatName.UpperCase();
85 TCollection_AsciiString anError;
86 TDF_Label anUnknownLabel = TDF_Label();
89 if (aFormatName == "BREP") {
90 aShape = BREPImport::Import(aFileName, aFormatName, anError, anUnknownLabel);
91 } else if (aFormatName == "STEP" || aFormatName == "STP") {
92 aShape = STEPImport::Import(aFileName, aFormatName, anError, anUnknownLabel);
93 } else if (aFormatName == "IGES") {
94 aShape = IGESImport::Import(aFileName, aFormatName, anError, anUnknownLabel);
96 // Check if shape is valid
97 if ( aShape.IsNull() ) {
98 const static std::string aShapeError =
99 "An error occurred while importing " + theFileName + ": " + anError.ToCString();
100 setError(aShapeError);
104 // Pass the results into the model
105 std::string anObjectName = aPath.Name().ToCString();
106 data()->setName(anObjectName);
107 std::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data());
108 std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
109 aGeomShape->setImpl(new TopoDS_Shape(aShape));
111 //LoadNamingDS of the imported shape
112 loadNamingDS(aGeomShape, aResultBody);
114 setResult(aResultBody);
119 //============================================================================
120 void ExchangePlugin_ImportFeature::loadNamingDS(
121 std::shared_ptr<GeomAPI_Shape> theGeomShape,
122 std::shared_ptr<ModelAPI_ResultBody> theResultBody)
125 theResultBody->store(theGeomShape);
128 std::string aNameMS = "Shape";
129 theResultBody->loadFirstLevel(theGeomShape, aNameMS, aTag);
130 //std::string aNameDE = "DiscEdges";
131 //theResultBody->loadDisconnectedEdges(theGeomShape, aNameDE, aTag);
132 //std::string aNameDV = "DiscVertexes";
133 //theResultBody->loadDisconnectedVertexes(theGeomShape, aNameDV, aTag);