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>
14 #include <GeomAPI_Shape.h>
15 #include <Config_Common.h>
16 #include <Config_PropManager.h>
18 #include <ModelAPI_AttributeString.h>
19 #include <ModelAPI_Data.h>
20 #include <ModelAPI_Document.h>
21 #include <ModelAPI_Object.h>
22 #include <ModelAPI_ResultBody.h>
23 #include <TCollection_AsciiString.hxx>
24 #include <TDF_Label.hxx>
25 #include <TopoDS_Shape.hxx>
26 #include <OSD_Path.hxx>
35 ExchangePlugin_ImportFeature::ExchangePlugin_ImportFeature()
39 ExchangePlugin_ImportFeature::~ExchangePlugin_ImportFeature()
41 // TODO Auto-generated destructor stub
45 * Returns the unique kind of a feature
47 const std::string& ExchangePlugin_ImportFeature::getKind()
49 return ExchangePlugin_ImportFeature::ID();
53 * Request for initialization of data model of the feature: adding all attributes
55 void ExchangePlugin_ImportFeature::initAttributes()
57 data()->addAttribute(ExchangePlugin_ImportFeature::FILE_PATH_ID(), ModelAPI_AttributeString::typeId());
61 * Computes or recomputes the results
63 void ExchangePlugin_ImportFeature::execute()
65 AttributeStringPtr aFilePathAttr = std::dynamic_pointer_cast<ModelAPI_AttributeString>(
66 data()->attribute(ExchangePlugin_ImportFeature::FILE_PATH_ID()));
67 std::string aFilePath = aFilePathAttr->value();
70 importFile(aFilePath);
73 bool ExchangePlugin_ImportFeature::importFile(const std::string& theFileName)
75 // retrieve the file and plugin library names
76 TCollection_AsciiString aFileName (theFileName.c_str());
77 OSD_Path aPath(aFileName);
78 TCollection_AsciiString aFormatName = aPath.Extension();
79 // ".brep" -> "BREP", TCollection_AsciiString are numbered from 1
80 aFormatName = aFormatName.SubString(2, aFormatName.Length());
81 aFormatName.UpperCase();
84 TCollection_AsciiString anError;
85 TDF_Label anUnknownLabel = TDF_Label();
88 if (aFormatName == "BREP") {
89 aShape = BREPImport::Import(aFileName, aFormatName, anError, anUnknownLabel);
90 } else if (aFormatName == "STEP") {
91 aShape = STEPImport::Import(aFileName, aFormatName, anError, anUnknownLabel);
93 // Check if shape is valid
94 if ( aShape.IsNull() ) {
95 const static std::string aShapeError =
96 "An error occurred while importing " + theFileName + ": " + anError.ToCString();
97 setError(aShapeError);
101 // Pass the results into the model
102 std::string anObjectName = aPath.Name().ToCString();
103 data()->setName(anObjectName);
104 std::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data());
105 std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
106 aGeomShape->setImpl(new TopoDS_Shape(aShape));
108 //LoadNamingDS of the imported shape
109 loadNamingDS(aGeomShape, aResultBody);
111 setResult(aResultBody);
116 //============================================================================
117 void ExchangePlugin_ImportFeature::loadNamingDS(
118 std::shared_ptr<GeomAPI_Shape> theGeomShape,
119 std::shared_ptr<ModelAPI_ResultBody> theResultBody)
122 theResultBody->store(theGeomShape);
125 std::string aNameMS = "Shape";
126 theResultBody->loadFirstLevel(theGeomShape, aNameMS, aTag);
127 //std::string aNameDE = "DiscEdges";
128 //theResultBody->loadDisconnectedEdges(theGeomShape, aNameDE, aTag);
129 //std::string aNameDV = "DiscVertexes";
130 //theResultBody->loadDisconnectedVertexes(theGeomShape, aNameDV, aTag);