1 // Name : ExchangeAPI_Import.cpp
5 // 07/06/16 - Sergey POKHODENKO - Creation of the file
7 //--------------------------------------------------------------------------------------
8 #include "ExchangeAPI_Import.h"
9 //--------------------------------------------------------------------------------------
10 #include <ModelHighAPI_Dumper.h>
11 #include <ModelHighAPI_Tools.h>
12 //--------------------------------------------------------------------------------------
15 ExchangeAPI_Import::ExchangeAPI_Import(
16 const std::shared_ptr<ModelAPI_Feature> & theFeature)
17 : ModelHighAPI_Interface(theFeature)
22 ExchangeAPI_Import::ExchangeAPI_Import(
23 const std::shared_ptr<ModelAPI_Feature> & theFeature,
24 const std::string & theFilePath)
25 : ModelHighAPI_Interface(theFeature)
28 setFilePath(theFilePath);
31 ExchangeAPI_Import::~ExchangeAPI_Import()
36 //--------------------------------------------------------------------------------------
37 void ExchangeAPI_Import::setFilePath(const std::string & theFilePath)
39 fillAttribute(theFilePath, myfilePath);
44 //--------------------------------------------------------------------------------------
45 void ExchangeAPI_Import::dump(ModelHighAPI_Dumper& theDumper) const
47 FeaturePtr aBase = feature();
48 std::string aPartName = theDumper.name(aBase->document());
50 std::string aFilePath = aBase->string(ExchangePlugin_ImportFeature::FILE_PATH_ID())->value();
51 std::string aFrom = "\\";
52 std::string aTo = "\\\\";
53 for(std::size_t aPos = aFilePath.find(aFrom);
54 aPos != std::string::npos;
55 aPos = aFilePath.find(aFrom, aPos)) {
56 aFilePath.replace(aPos, aFrom.size(), aTo);
60 theDumper << aBase << " = model.addImport(" << aPartName << ", \""
61 << aFilePath << "\")" << std::endl;
62 // to make import have results
63 theDumper << "model.do()" << std::endl;
65 CompositeFeaturePtr aCompositeFeature = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aBase);
66 if(aCompositeFeature.get()) {
67 int aNbOfSubs = aCompositeFeature->numberOfSubs();
68 for(int anIndex = 0; anIndex < aNbOfSubs; ++anIndex) {
69 std::string aSubFeatureGet = theDumper.name(aBase) + ".subFeature(" + std::to_string((long long)anIndex) + ")";
70 theDumper.dumpSubFeatureNameAndColor(aSubFeatureGet, aCompositeFeature->subFeature(anIndex));
75 //--------------------------------------------------------------------------------------
77 const std::shared_ptr<ModelAPI_Document> & thePart,
78 const std::string & theFilePath)
80 // TODO(spo): check that thePart is not empty
81 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ExchangeAPI_Import::ID());
82 return ImportPtr(new ExchangeAPI_Import(aFeature, theFilePath));