]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Flushing created and updated events instead of calling execute on feature in ModelHig...
authordbv <dbv@opencascade.com>
Tue, 23 Aug 2016 07:01:55 +0000 (10:01 +0300)
committerdbv <dbv@opencascade.com>
Tue, 23 Aug 2016 07:02:22 +0000 (10:02 +0300)
Fixed TestImport

src/ExchangeAPI/ExchangeAPI_Import.cpp
src/ModelHighAPI/ModelHighAPI_Dumper.cpp
src/ModelHighAPI/ModelHighAPI_Dumper.h
src/ModelHighAPI/ModelHighAPI_Interface.cpp
src/ModelHighAPI/ModelHighAPI_Interface.h

index 87eb4410d0333815e83daeaf6147ba6921f94ac7..76e818ebb511a51c4eff4ee8978879407d1ae05c 100644 (file)
@@ -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<ModelAPI_CompositeFeature>(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));
+    }
+  }
 }
 
 //--------------------------------------------------------------------------------------
index 3799f614f9480808a208b22662a8ad96206d4d04..633984d81b7cc21d7924303c8ac6b7d0273633df 100644 (file)
@@ -284,6 +284,28 @@ bool ModelHighAPI_Dumper::processSubs(const std::shared_ptr<ModelAPI_CompositeFe
   return isOk;
 }
 
+void ModelHighAPI_Dumper::dumpSubFeatureNameAndColor(const std::string theSubFeatureGet,
+                                                     const FeaturePtr& theSubFeature)
+{
+  name(theSubFeature, false);
+  myNames[theSubFeature] = std::pair<std::string, std::string>(theSubFeatureGet, theSubFeature->name());
+
+  // store results if they have user-defined names or colors
+  std::list<ResultPtr> aResultsWithNameOrColor;
+  const std::list<ResultPtr>& aResults = theSubFeature->results();
+  std::list<ResultPtr>::const_iterator aResIt = aResults.begin();
+  for (; aResIt != aResults.end(); ++aResIt) {
+    std::string aResName = (*aResIt)->data()->name();
+    myNames[*aResIt] = std::pair<std::string, std::string>(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;
index 181c3800ef5557c492cb95fcfa9c7c52b0ffe59f..5231ffe7331753382caecebe8bf243eadfa1efdb 100644 (file)
@@ -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;
index aadac128acfcce1e46e149809a5a7188e7ab7c49..401ba5467ed6f5a64f615c07ecb271b77b7dfd7e 100644 (file)
@@ -9,6 +9,8 @@
 //--------------------------------------------------------------------------------------
 #include <Events_InfoMessage.h>
 
+#include <ModelAPI_CompositeFeature.h>
+#include <ModelAPI_Events.h>
 #include <ModelAPI_Feature.h>
 #include <ModelAPI_Session.h>
 #include <ModelAPI_Validator.h>
@@ -32,6 +34,21 @@ std::shared_ptr<ModelAPI_Feature> ModelHighAPI_Interface::feature() const
   return myFeature;
 }
 
+std::shared_ptr<ModelHighAPI_Interface> ModelHighAPI_Interface::subFeature(const int theIndex) const
+{
+  CompositeFeaturePtr aCompositeFeature = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(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)
index 4dd2bca21a0d140e2ddd1e931c1391800986038a..f4c156fb756d7ceaedd30ca7754cfbece4d9cdca 100644 (file)
@@ -39,6 +39,11 @@ public:
   MODELHIGHAPI_EXPORT
   std::shared_ptr<ModelAPI_Feature> 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<ModelHighAPI_Interface> subFeature(const int theIndex) const;
+
   /// Shortcut for feature()->getKind()
   MODELHIGHAPI_EXPORT
   const std::string& getKind() const;