]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Linux compilation and isPreviewNeeded method implementation.
authormpv <mpv@opencascade.com>
Tue, 19 May 2015 06:29:35 +0000 (09:29 +0300)
committermpv <mpv@opencascade.com>
Tue, 19 May 2015 06:29:35 +0000 (09:29 +0300)
src/Model/Model_Objects.cpp
src/Model/Model_Objects.h
src/Model/Model_Update.cpp
src/Model/Model_Update.h
src/ModelAPI/ModelAPI_Feature.cpp
src/ModelAPI/ModelAPI_Feature.h

index 0f661c8745848fba76c27e42979e7d17c0a4f563..e87508864abad949886e2070b4001a5f18c5b833 100644 (file)
@@ -299,7 +299,7 @@ void Model_Objects::updateHistory(const std::string theGroup)
     myHistory.erase(aHIter); // erase from map => this means that it is not synchronized
 }
 
-FeaturePtr Model_Objects::feature(TDF_Label& theLabel) const
+FeaturePtr Model_Objects::feature(TDF_Label theLabel) const
 {
   if (myFeatures.IsBound(theLabel))
     return myFeatures.Find(theLabel);
index 06848a8584b7e3850c675b28792fd7628b14bb6c..148c1c22a4e29a13f79ce1579de1bc2cbc5a5ed2 100644 (file)
@@ -53,7 +53,7 @@ class Model_Objects
 
   //! Returns the existing feature by the label
   //! \param theLabel base label of the feature
-  FeaturePtr feature(TDF_Label& theLabel) const;
+  FeaturePtr feature(TDF_Label theLabel) const;
 
   //! Returns the existing object: result or feature
   //! \param theLabel base label of the object
index faa0ec14b6bba6ed3f4fe490a11e277c31d06de9..c560fa4ba9943b9580b4d4abdcd65ead47b2b851 100644 (file)
@@ -111,8 +111,19 @@ void Model_Update::processEvent(const std::shared_ptr<Events_Message>& theMessag
     for(; aCreatedIter != myJustCreated.end(); aCreatedIter++) {
       FeaturePtr aFeature = 
         std::dynamic_pointer_cast<ModelAPI_Feature>(*aCreatedIter);
-      if (aFeature.get() && aFeature->isMacro()) {
-        aFeature->document()->removeFeature(aFeature);
+      if (aFeature.get()) {
+        // execute not-previewed feature on "apply"
+        if (!aFeature->isPreviewNeeded() && (myJustCreated.find(aFeature) != myJustCreated.end() ||
+          myJustUpdated.find(aFeature) != myJustUpdated.end())) {
+          static ModelAPI_ValidatorsFactory* aFactory = ModelAPI_Session::get()->validators();
+          if (aFactory->validate(aFeature)) {
+            executeFeature(aFeature);
+          }
+        }
+        // remove macro on apply
+        if (aFeature->isMacro()) {
+          aFeature->document()->removeFeature(aFeature);
+        }
       }
     }
     myJustCreated.clear();
@@ -346,33 +357,16 @@ void Model_Update::updateFeature(FeaturePtr theFeature)
     //std::cout<<"Update feature "<<theFeature->getKind()<<" must be updated = "<<aMustbeUpdated<<std::endl;
     // execute feature if it must be updated
     if (aJustUpdated) {
-      if (std::dynamic_pointer_cast<Model_Document>(theFeature->document())->executeFeatures() ||
-          !theFeature->isPersistentResult()) {
+      if ((std::dynamic_pointer_cast<Model_Document>(theFeature->document())->executeFeatures() ||
+          !theFeature->isPersistentResult()) && theFeature->isPreviewNeeded()) {
         if (aFactory->validate(theFeature)) {
           if (myIsAutomatic || 
               (myJustCreated.find(theFeature) != myJustCreated.end() ||
               !theFeature->isPersistentResult() /* execute quick, not persistent results */))
           {
-            // execute in try-catch to avoid internal problems of the feature
             if (aState == ModelAPI_StateDone || aState == ModelAPI_StateMustBeUpdated) {
-              theFeature->data()->execState(ModelAPI_StateDone);
-              try {
-                theFeature->execute();
-                if (theFeature->data()->execState() != ModelAPI_StateDone) {
-                  aState = ModelAPI_StateExecFailed;
-                } else {
-                  aState = ModelAPI_StateDone;
-                }
-              } catch(...) {
-                aState = ModelAPI_StateExecFailed;
-                Events_Error::send(
-                  "Feature " + theFeature->getKind() + " has failed during the execution");
-              }
-            }
-            if (aState != ModelAPI_StateDone) {
-              theFeature->eraseResults();
+              executeFeature(theFeature);
             }
-            redisplayWithResults(theFeature, aState);
           } else { // must be updatet, but not updated yet
             theFeature->data()->execState(ModelAPI_StateMustBeUpdated);
             const std::list<std::shared_ptr<ModelAPI_Result> >& aResults = theFeature->results();
@@ -392,3 +386,27 @@ void Model_Update::updateFeature(FeaturePtr theFeature)
     }
   }
 }
+
+void Model_Update::executeFeature(FeaturePtr theFeature)
+{
+  // execute in try-catch to avoid internal problems of the feature
+  ModelAPI_ExecState aState = ModelAPI_StateDone;
+  theFeature->data()->execState(ModelAPI_StateDone);
+  try {
+    theFeature->execute();
+    if (theFeature->data()->execState() != ModelAPI_StateDone) {
+      aState = ModelAPI_StateExecFailed;
+    } else {
+      aState = ModelAPI_StateDone;
+    }
+  } catch(...) {
+    aState = ModelAPI_StateExecFailed;
+    Events_Error::send(
+      "Feature " + theFeature->getKind() + " has failed during the execution");
+  }
+  if (aState != ModelAPI_StateDone) {
+    theFeature->eraseResults();
+  }
+  redisplayWithResults(theFeature, aState);
+}
+
index 89141313b1f36437c982cddac479bb4648d15fce..22fe573b9c061cc39282cd60d6b25f19f81a4e30 100644 (file)
@@ -56,6 +56,10 @@ protected:
   /// On operation start/end/abort the "Just" fileds must be cleared and processed in the right way
   /// \param theTotalUpdate force to updates everything that has been changed in this operation
   void processOperation(const bool theTotalUpdate);
+
+  /// Performs the feature execution
+  /// \returns the status of execution
+  void executeFeature(std::shared_ptr<ModelAPI_Feature> theFeature);
 };
 
 #endif
index e7c16599ae42d42511122de5bb4cd9c1a8633d3f..3a85d388a2e54262679958aa408957f8c581f950 100644 (file)
@@ -146,3 +146,8 @@ bool ModelAPI_Feature::isDisabled() const
 {
   return myIsDisabled;
 }
+
+bool ModelAPI_Feature::isPreviewNeeded() const
+{
+  return true;
+}
index c2f34865b18080e5fa17ad824a0895396294e4ee..72d58660dadb2ccbd6cfca172c189d0e70afa59a 100644 (file)
@@ -104,6 +104,11 @@ class ModelAPI_Feature : public ModelAPI_Object
   /// \returns false by default
   MODELAPI_EXPORT virtual bool isMacro() const;
 
+  /// Returns true if preview update during the edition needed. Otherwise the update-mechanism
+  /// calls the \a execute function only on "apply" of the operation
+  /// \returns true by default
+  MODELAPI_EXPORT virtual bool isPreviewNeeded() const;
+
   /// Must return document where the new feature must be added to
   /// By default it is empty: it is added to the document this method is called to
   MODELAPI_EXPORT virtual const std::string& documentToAdd();