From 540e8b84d9123ec7b3f0603b38df6ed8f8e86516 Mon Sep 17 00:00:00 2001 From: dbv Date: Tue, 23 Aug 2016 10:01:55 +0300 Subject: [PATCH] Flushing created and updated events instead of calling execute on feature in ModelHighAPI_Interface::execute Fixed TestImport --- src/ExchangeAPI/ExchangeAPI_Import.cpp | 11 +++++++ src/ModelHighAPI/ModelHighAPI_Dumper.cpp | 22 +++++++++++++ src/ModelHighAPI/ModelHighAPI_Dumper.h | 8 +++++ src/ModelHighAPI/ModelHighAPI_Interface.cpp | 35 +++++++++++++++++---- src/ModelHighAPI/ModelHighAPI_Interface.h | 5 +++ 5 files changed, 75 insertions(+), 6 deletions(-) diff --git a/src/ExchangeAPI/ExchangeAPI_Import.cpp b/src/ExchangeAPI/ExchangeAPI_Import.cpp index 87eb4410d..76e818ebb 100644 --- a/src/ExchangeAPI/ExchangeAPI_Import.cpp +++ b/src/ExchangeAPI/ExchangeAPI_Import.cpp @@ -47,6 +47,17 @@ void ExchangeAPI_Import::dump(ModelHighAPI_Dumper& theDumper) const theDumper << aBase << " = model.addImport(" << aPartName << ", " << aBase->string(ExchangePlugin_ImportFeature::FILE_PATH_ID()) << ")" << std::endl; + // to make import have results + theDumper << "model.do()" << std::endl; + + CompositeFeaturePtr aCompositeFeature = std::dynamic_pointer_cast(aBase); + if(aCompositeFeature.get()) { + int aNbOfSubs = aCompositeFeature->numberOfSubs(); + for(int anIndex = 0; anIndex < aNbOfSubs; ++anIndex) { + std::string aSubFeatureGet = theDumper.name(aBase) + ".subFeature(" + std::to_string((long long)anIndex) + ")"; + theDumper.dumpSubFeatureNameAndColor(aSubFeatureGet, aCompositeFeature->subFeature(anIndex)); + } + } } //-------------------------------------------------------------------------------------- diff --git a/src/ModelHighAPI/ModelHighAPI_Dumper.cpp b/src/ModelHighAPI/ModelHighAPI_Dumper.cpp index 3799f614f..633984d81 100644 --- a/src/ModelHighAPI/ModelHighAPI_Dumper.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Dumper.cpp @@ -284,6 +284,28 @@ bool ModelHighAPI_Dumper::processSubs(const std::shared_ptr(theSubFeatureGet, theSubFeature->name()); + + // store results if they have user-defined names or colors + std::list aResultsWithNameOrColor; + const std::list& aResults = theSubFeature->results(); + std::list::const_iterator aResIt = aResults.begin(); + for (; aResIt != aResults.end(); ++aResIt) { + std::string aResName = (*aResIt)->data()->name(); + myNames[*aResIt] = std::pair(aResName, aResName); + aResultsWithNameOrColor.push_back(*aResIt); + } + + // store just dumped entity to stack + myEntitiesStack.push(LastDumpedEntity(theSubFeature, true, aResultsWithNameOrColor)); + + dumpEntitySetName(); +} + bool ModelHighAPI_Dumper::exportTo(const std::string& theFileName) { std::ofstream aFile; diff --git a/src/ModelHighAPI/ModelHighAPI_Dumper.h b/src/ModelHighAPI/ModelHighAPI_Dumper.h index 181c3800e..5231ffe73 100644 --- a/src/ModelHighAPI/ModelHighAPI_Dumper.h +++ b/src/ModelHighAPI/ModelHighAPI_Dumper.h @@ -98,6 +98,14 @@ public: /// Dump given feature virtual void dumpFeature(const FeaturePtr& theFeature, const bool theForce = false) = 0; + /// Dump sub-feature name and color, without dumping feature creation. + /// Used for features which creates sub-features in their execute method. + /// \param theSubFeatureGet [in] method for getting sub-feature (e.g. "Feature_1.subFeature(0)") + /// \param theSubFeature [in] sub-feature + MODELHIGHAPI_EXPORT + void dumpSubFeatureNameAndColor(const std::string theSubFeatureGet, + const FeaturePtr& theSubFeature); + /// Return name of getter for corresponding attribute virtual std::string attributeGetter(const FeaturePtr& theFeature, const std::string& theAttrName) const = 0; diff --git a/src/ModelHighAPI/ModelHighAPI_Interface.cpp b/src/ModelHighAPI/ModelHighAPI_Interface.cpp index aadac128a..401ba5467 100644 --- a/src/ModelHighAPI/ModelHighAPI_Interface.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Interface.cpp @@ -9,6 +9,8 @@ //-------------------------------------------------------------------------------------- #include +#include +#include #include #include #include @@ -32,6 +34,21 @@ std::shared_ptr ModelHighAPI_Interface::feature() const return myFeature; } +std::shared_ptr ModelHighAPI_Interface::subFeature(const int theIndex) const +{ + CompositeFeaturePtr aCompositeFeature = std::dynamic_pointer_cast(myFeature); + if(!aCompositeFeature.get()) { + return InterfacePtr(); + } + + FeaturePtr aSubFeature = aCompositeFeature->subFeature(theIndex); + if(!aSubFeature.get()) { + return InterfacePtr(); + } + + return InterfacePtr(new ModelHighAPI_Interface(aSubFeature)); +} + const std::string& ModelHighAPI_Interface::getKind() const { return feature()->getKind(); @@ -39,12 +56,18 @@ const std::string& ModelHighAPI_Interface::getKind() const void ModelHighAPI_Interface::execute() { - SessionPtr aMgr = ModelAPI_Session::get(); - ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); - FeaturePtr aFeature = feature(); - if(aFactory->validate(aFeature)) { - aFeature->execute(); - } + //SessionPtr aMgr = ModelAPI_Session::get(); + //ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); + //FeaturePtr aFeature = feature(); + //if(aFactory->validate(aFeature)) { + // aFeature->execute(); + //} + + Events_Loop* aLoop = Events_Loop::loop(); + aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED)); + aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); + //aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); + //aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_DELETED)); } void ModelHighAPI_Interface::setName(const std::string& theName) diff --git a/src/ModelHighAPI/ModelHighAPI_Interface.h b/src/ModelHighAPI/ModelHighAPI_Interface.h index 4dd2bca21..f4c156fb7 100644 --- a/src/ModelHighAPI/ModelHighAPI_Interface.h +++ b/src/ModelHighAPI/ModelHighAPI_Interface.h @@ -39,6 +39,11 @@ public: MODELHIGHAPI_EXPORT std::shared_ptr feature() const; + /// If feature is composite return intefrace for sub-feature by zero-based index, + /// or empty pointer if feature not composite or does not have sub-feature with such index. + MODELHIGHAPI_EXPORT + std::shared_ptr subFeature(const int theIndex) const; + /// Shortcut for feature()->getKind() MODELHIGHAPI_EXPORT const std::string& getKind() const; -- 2.39.2