]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Make circle with radius 0 not crashed: check validity before execution
authormpv <mikhail.ponikarov@opencascade.com>
Thu, 4 Sep 2014 10:29:25 +0000 (14:29 +0400)
committermpv <mikhail.ponikarov@opencascade.com>
Thu, 4 Sep 2014 10:29:25 +0000 (14:29 +0400)
src/ExchangePlugin/ExchangePlugin_ImportFeature.h
src/Model/Model_Data.cpp
src/Model/Model_Data.h
src/Model/Model_Update.cpp
src/ModelAPI/ModelAPI_Data.h
src/ModelAPI/ModelAPI_Feature.cpp
src/ModelAPI/ModelAPI_Feature.h
src/SketchPlugin/SketchPlugin_Plugin.cpp
src/SketchPlugin/SketchPlugin_Validators.cpp
src/SketchPlugin/SketchPlugin_Validators.h
src/SketchPlugin/plugin-Sketch.xml

index 4b3b7a80399296265a19a91a5fcae668d2ef024e..3745d16607caaa0f0b9c7565538c6c4cf276921b 100644 (file)
@@ -27,7 +27,7 @@
 #define UnLoadLib( handle ) dlclose( handle );
 #endif
 
-class EXCHANGEPLUGIN_EXPORT ExchangePlugin_ImportFeature : public ModelAPI_Feature
+class ExchangePlugin_ImportFeature : public ModelAPI_Feature
 {
  public:
   /// Extrusion kind
@@ -43,26 +43,26 @@ class EXCHANGEPLUGIN_EXPORT ExchangePlugin_ImportFeature : public ModelAPI_Featu
     return MY_FILE_PATH_ID;
   }
 
-  ExchangePlugin_ImportFeature();
-  virtual ~ExchangePlugin_ImportFeature();
+  EXCHANGEPLUGIN_EXPORT ExchangePlugin_ImportFeature();
+  EXCHANGEPLUGIN_EXPORT virtual ~ExchangePlugin_ImportFeature();
 
   /// Returns the unique kind of a feature
-  virtual const std::string& getKind();
+  EXCHANGEPLUGIN_EXPORT virtual const std::string& getKind();
 
   /// Request for initialization of data model of the feature: adding all attributes
-  virtual void initAttributes();
+  EXCHANGEPLUGIN_EXPORT virtual void initAttributes();
 
   /// Computes or recomputes the results
-  virtual void execute();
+  EXCHANGEPLUGIN_EXPORT virtual void execute();
 
-  virtual bool isInHistory()
+  EXCHANGEPLUGIN_EXPORT virtual bool isInHistory()
   {
     return false;
   }
 
  protected:
-  bool importFile(const std::string& theFileName);
-  LibHandle loadImportPlugin(const std::string& theFormatName);
+  EXCHANGEPLUGIN_EXPORT bool importFile(const std::string& theFileName);
+  EXCHANGEPLUGIN_EXPORT LibHandle loadImportPlugin(const std::string& theFormatName);
   
 };
 
index 7813c461f4f869b49a2bbfd3a95bcdbc6c262deb..5dba72cbdc74460c305b2bf275f7db5e24e4e7b7 100644 (file)
@@ -282,3 +282,9 @@ void Model_Data::sendAttributeUpdated(ModelAPI_Attribute* theAttr)
     ModelAPI_EventCreator::get()->sendUpdated(myObject, anEvent);
   }
 }
+
+void Model_Data::erase()
+{
+  if (!myLab.IsNull())
+    myLab.ForgetAllAttributes();
+}
index f8ad2f0a73b214aa0e5a5e5582a63740d2791b4e..f6a82a09906f80e170dfbf503302a240478dc431 100644 (file)
@@ -127,6 +127,8 @@ class Model_Data : public ModelAPI_Data
   {
     myObject = theObject;
   }
+
+  MODEL_EXPORT virtual void erase();
 };
 
 #endif
index a5747140567767a2cdbed087cfd3238b516b8e0e..9b76e5f5aa0607669fa9092b29248f07b9ba0eaa 100644 (file)
@@ -11,6 +11,7 @@
 #include <ModelAPI_AttributeReference.h>
 #include <ModelAPI_AttributeRefList.h>
 #include <ModelAPI_Result.h>
+#include <ModelAPI_Validator.h>
 #include <Events_Loop.h>
 #include <Events_LongOp.h>
 
@@ -94,8 +95,14 @@ bool Model_Update::updateFeature(FeaturePtr theFeature)
     if (aMustbeUpdated) {
 
       if (boost::dynamic_pointer_cast<Model_Document>(theFeature->document())->executeFeatures() ||
-          !theFeature->isPersistentResult())
-        theFeature->execute();
+          !theFeature->isPersistentResult()) {
+        ModelAPI_ValidatorsFactory* aFactory = ModelAPI_PluginManager::get()->validators();
+        if (aFactory->validate(theFeature)) {
+          theFeature->execute();
+        } else {
+          theFeature->eraseResults();
+        }
+      }
       // redisplay all results
       static Events_ID EVENT_DISP = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
       const std::list<boost::shared_ptr<ModelAPI_Result> >& aResults = theFeature->results();
index c4fe4712f1f5ce7dedcee88a4c451b617d12a9b8..2daf2302b7e52dbe9f01a6db68d5857b646e9566 100644 (file)
@@ -83,6 +83,9 @@ class MODELAPI_EXPORT ModelAPI_Data
   /// makes attribute initialized
   virtual void sendAttributeUpdated(ModelAPI_Attribute* theAttr) = 0;
 
+  /// Erases all the data from the data model
+  virtual void erase() = 0;
+
   /// To virtually destroy the fields of successors
   virtual ~ModelAPI_Data()
   {
index 158675e9f1272443c9acbcbcda09dc0a2d674434..796bf5b0bffd3618fcdfec6bdd50b34540792db2 100644 (file)
@@ -5,6 +5,7 @@
 #include "ModelAPI_Feature.h"
 #include <ModelAPI_Events.h>
 #include <ModelAPI_Result.h>
+#include <ModelAPI_Data.h>
 #include <ModelAPI_Document.h>
 #include <Events_Loop.h>
 
@@ -63,11 +64,27 @@ void ModelAPI_Feature::removeResult(const boost::shared_ptr<ModelAPI_Result>& th
   std::list<boost::shared_ptr<ModelAPI_Result> >::iterator aResIter = myResults.begin();
   for(; aResIter != myResults.end(); aResIter++) {
     if (*aResIter == theResult) {
+      std::string aGroup = (*aResIter)->groupName();
+      (*aResIter)->data()->erase();
       myResults.erase(aResIter);
+      static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_DELETED);
+      ModelAPI_EventCreator::get()->sendDeleted(document(), aGroup);
+      break;
     }
   }
 }
 
+void ModelAPI_Feature::eraseResults()
+{
+  std::list<boost::shared_ptr<ModelAPI_Result> >::iterator aResIter = myResults.begin();
+  for(; aResIter != myResults.end(); aResIter++) {
+      (*aResIter)->data()->erase();
+      static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_DELETED);
+      ModelAPI_EventCreator::get()->sendDeleted(document(), (*aResIter)->groupName());
+  }
+  myResults.clear();
+}
+
 boost::shared_ptr<ModelAPI_Document> ModelAPI_Feature::documentToAdd()
 {
   return ModelAPI_PluginManager::get()->currentDocument();
index fed0ea648f23df84e25a481634f6f71518b555c5..ef1212afc7156b1f32412d5315fe2ed080f330e3 100644 (file)
@@ -59,6 +59,8 @@ class ModelAPI_Feature : public ModelAPI_Object
                                  const int theIndex);
   /// removes the result from the feature
   MODELAPI_EXPORT void removeResult(const boost::shared_ptr<ModelAPI_Result>& theResult);
+  /// removes all results from the feature
+  MODELAPI_EXPORT void eraseResults();
 
   /// Returns true if result is persistent (stored in document) and on undo-redo, save-open
   /// it is not needed to recompute it.
index 930253dad1f502a3e281b4183bcad9282fba9a43..6fcb0c4003277fb5eaeaa6096119847b25ff003a 100644 (file)
@@ -29,6 +29,8 @@ SketchPlugin_Plugin::SketchPlugin_Plugin()
   ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
   aFactory->registerValidator("SketchPlugin_DistanceAttrValidator",
                               new SketchPlugin_DistanceAttrValidator);
+  aFactory->registerValidator("SketchPlugin_RadiusValidator",
+                              new SketchPlugin_RadiusValidator);
   aFactory->registerValidator("SketchPlugin_ResultPointValidator", new SketchPlugin_ResultPointValidator);
   aFactory->registerValidator("SketchPlugin_ResultLineValidator", new SketchPlugin_ResultLineValidator);
   aFactory->registerValidator("SketchPlugin_ResultArcValidator", new SketchPlugin_ResultArcValidator);
index 4115d11a4038b0ae522376672b847ddd0fae4d3e..7880ff0338e266cc96f291e85eac542d462fb652 100644 (file)
@@ -7,6 +7,7 @@
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Validator.h>
 #include <ModelAPI_ResultValidator.h>
+#include <ModelAPI_AttributeDouble.h>
 #include <GeomDataAPI_Point2D.h>
 
 bool SketchPlugin_DistanceAttrValidator::isValid(const FeaturePtr& theFeature,
@@ -42,3 +43,11 @@ bool SketchPlugin_DistanceAttrValidator::isValid(
   }
   return true; // it may be not reference attribute, in this case, it is OK
 }
+
+bool SketchPlugin_RadiusValidator::isValid(
+    const AttributePtr& theAttribute, const std::list<std::string>& theArguments) const
+{
+  boost::shared_ptr<ModelAPI_AttributeDouble> aDouble = 
+    boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(theAttribute);
+  return aDouble->isInitialized() && aDouble->value() > 1.e-5;
+}
index 4da0f73e92f21641a304fb8a98ea75aecfe71ff0..8a5a82bb04a3f30f5bd76b90361a60548f778c28 100644 (file)
@@ -8,7 +8,7 @@
 #include "SketchPlugin.h"
 #include <ModelAPI_RefAttrValidator.h>
 
-class SketchPlugin_DistanceAttrValidator : public ModelAPI_AttributeValidator
+class SketchPlugin_DistanceAttrValidator : public ModelAPI_RefAttrValidator
 {
  public:
   //! returns true if attribute is valid
@@ -22,4 +22,18 @@ class SketchPlugin_DistanceAttrValidator : public ModelAPI_AttributeValidator
 
 };
 
+/**
+ * It must be bigger than 1.e-5
+ */
+class SketchPlugin_RadiusValidator : public ModelAPI_AttributeValidator
+{
+ public:
+  //! returns true if attribute is valid
+  //! \param theAttribute the checked attribute
+  //! \param theArguments arguments of the attribute
+  virtual bool isValid(
+    const AttributePtr& theAttribute, const std::list<std::string>& theArguments) const;
+
+};
+
 #endif
index 7c26e28e2df70a23a02879c8e4100e4d01fa572f..4c1d80a06369662d3922fdbc5648174a9d7268ef 100644 (file)
@@ -14,7 +14,9 @@
       </feature>
       <feature id="SketchCircle" title="Circle" tooltip="Create a new circle" icon=":icons/circle.png">
         <point_selector id="CircleCenter" title="Center" tooltip="Center of the circle"/>
-        <point2ddistance id="CircleRadius" first_point="CircleCenter" label="Radius:" min="0" step="1.0" default="0" icon=":icons/radius.png" tooltip="Set Radius"/>
+        <point2ddistance id="CircleRadius" first_point="CircleCenter" label="Radius:" min="0" step="1.0" default="0" icon=":icons/radius.png" tooltip="Set Radius">
+          <validator id="SketchPlugin_RadiusValidator"/>
+        </point2ddistance>
       </feature>
       <feature id="SketchArc" title="Arc" tooltip="Create a new arc of a circle" icon=":icons/arc.png">
         <point_selector id="ArcCenter" title="Center" tooltip="Center of the arc"/>