1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // Name : ExchangeAPI_Import.cpp
7 // 07/06/16 - Sergey POKHODENKO - Creation of the file
9 //--------------------------------------------------------------------------------------
10 #include "ExchangeAPI_Import.h"
11 //--------------------------------------------------------------------------------------
12 #include <ModelHighAPI_Dumper.h>
13 #include <ModelHighAPI_Tools.h>
14 //--------------------------------------------------------------------------------------
17 ExchangeAPI_Import::ExchangeAPI_Import(
18 const std::shared_ptr<ModelAPI_Feature> & theFeature)
19 : ModelHighAPI_Interface(theFeature)
24 ExchangeAPI_Import::ExchangeAPI_Import(
25 const std::shared_ptr<ModelAPI_Feature> & theFeature,
26 const std::string & theFilePath)
27 : ModelHighAPI_Interface(theFeature)
30 setFilePath(theFilePath);
33 ExchangeAPI_Import::~ExchangeAPI_Import()
38 //--------------------------------------------------------------------------------------
39 void ExchangeAPI_Import::setFilePath(const std::string & theFilePath)
41 fillAttribute(theFilePath, myfilePath);
46 //--------------------------------------------------------------------------------------
47 void ExchangeAPI_Import::dump(ModelHighAPI_Dumper& theDumper) const
49 FeaturePtr aBase = feature();
50 std::string aPartName = theDumper.name(aBase->document());
52 std::string aFilePath = aBase->string(ExchangePlugin_ImportFeature::FILE_PATH_ID())->value();
53 std::string aFrom = "\\";
54 std::string aTo = "\\\\";
55 for(std::size_t aPos = aFilePath.find(aFrom);
56 aPos != std::string::npos;
57 aPos = aFilePath.find(aFrom, aPos)) {
58 aFilePath.replace(aPos, aFrom.size(), aTo);
62 theDumper << aBase << " = model.addImport(" << aPartName << ", \""
63 << aFilePath << "\")" << std::endl;
64 // to make import have results
65 theDumper << "model.do()" << std::endl;
67 CompositeFeaturePtr aCompositeFeature =
68 std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aBase);
69 if(aCompositeFeature.get()) {
70 int aNbOfSubs = aCompositeFeature->numberOfSubs();
71 for(int anIndex = 0; anIndex < aNbOfSubs; ++anIndex) {
72 std::string aSubFeatureGet =
73 theDumper.name(aBase) + ".subFeature(" + std::to_string((long long)anIndex) + ")";
74 theDumper.dumpSubFeatureNameAndColor(aSubFeatureGet, aCompositeFeature->subFeature(anIndex));
79 //--------------------------------------------------------------------------------------
81 const std::shared_ptr<ModelAPI_Document> & thePart,
82 const std::string & theFilePath)
84 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ExchangeAPI_Import::ID());
85 return ImportPtr(new ExchangeAPI_Import(aFeature, theFilePath));