]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Create validator for distance constraint
authorvsv <vitaly.smetannikov@opencascade.com>
Wed, 6 Aug 2014 13:42:11 +0000 (17:42 +0400)
committervsv <vitaly.smetannikov@opencascade.com>
Wed, 6 Aug 2014 13:42:11 +0000 (17:42 +0400)
51 files changed:
src/GeomAPI/GeomAPI_Shape.h
src/Model/CMakeLists.txt
src/Model/Model_ResultValidators.cpp [new file with mode: 0644]
src/Model/Model_ResultValidators.h [new file with mode: 0644]
src/Model/Model_Validator.cpp
src/Model/Model_Validator.h
src/ModelAPI/CMakeLists.txt
src/ModelAPI/ModelAPI_AttributeValidator.h [new file with mode: 0644]
src/ModelAPI/ModelAPI_Feature.cpp
src/ModelAPI/ModelAPI_Feature.h
src/ModelAPI/ModelAPI_ResultValidator.h [new file with mode: 0644]
src/ModelAPI/ModelAPI_Tools.cpp [new file with mode: 0644]
src/ModelAPI/ModelAPI_Tools.h [new file with mode: 0644]
src/ModelAPI/ModelAPI_Validator.h
src/ModuleBase/CMakeLists.txt
src/ModuleBase/ModuleBase_FeatureValidator.h [deleted file]
src/ModuleBase/ModuleBase_ModelWidget.h
src/ModuleBase/ModuleBase_Operation.cpp
src/ModuleBase/ModuleBase_Tools.cpp
src/ModuleBase/ModuleBase_WidgetBoolValue.cpp
src/ModuleBase/ModuleBase_WidgetBoolValue.h
src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp
src/ModuleBase/ModuleBase_WidgetDoubleValue.h
src/ModuleBase/ModuleBase_WidgetFeature.cpp
src/ModuleBase/ModuleBase_WidgetFeature.h
src/ModuleBase/ModuleBase_WidgetFeatureOrAttribute.cpp
src/ModuleBase/ModuleBase_WidgetFeatureOrAttribute.h
src/ModuleBase/ModuleBase_WidgetPoint2D.cpp
src/ModuleBase/ModuleBase_WidgetPoint2D.h
src/ModuleBase/ModuleBase_WidgetSelector.cpp
src/ModuleBase/ModuleBase_WidgetSelector.h
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_OperationFeatureEdit.cpp
src/PartSet/PartSet_OperationFeatureEditMulti.cpp
src/PartSet/PartSet_WidgetSketchLabel.h
src/SketchPlugin/CMakeLists.txt
src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp
src/SketchPlugin/SketchPlugin_ConstraintDistance.h
src/SketchPlugin/SketchPlugin_ConstraintLength.cpp
src/SketchPlugin/SketchPlugin_ConstraintParallel.cpp
src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.cpp
src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp
src/SketchPlugin/SketchPlugin_Plugin.cpp
src/SketchPlugin/SketchPlugin_Sketch.cpp
src/SketchPlugin/SketchPlugin_Sketch.h
src/SketchPlugin/SketchPlugin_Validators.cpp
src/SketchPlugin/SketchPlugin_Validators.h
src/SketchPlugin/plugin-Sketch.xml
src/XGUI/XGUI_Displayer.cpp
src/XGUI/XGUI_PropertyPanel.cpp
src/XGUI/XGUI_Workshop.cpp

index b557e845ed47cb50052b6d8d43923969ef0a90cc..9866616ccf9ebccb0469db2d0c0a173c43bd2fb5 100644 (file)
@@ -28,6 +28,7 @@ public:
 
   /// Returns whether the shape is an edge
   virtual bool isEdge() const;
+
 };
 
 #endif
index fdfb04ccf2ed7cc77bbac2f32f32d58fb3ea0dc5..45c3db89032839e88423b3c387d15ec3f321ad70 100644 (file)
@@ -18,6 +18,7 @@ SET(PROJECT_HEADERS
     Model_ResultBody.h
     Model_ResultConstruction.h
     Model_ResultPart.h
+       Model_ResultValidators.h
 )
 
 SET(PROJECT_SOURCES
@@ -37,6 +38,7 @@ SET(PROJECT_SOURCES
     Model_ResultBody.cpp
     Model_ResultConstruction.cpp
     Model_ResultPart.cpp
+       Model_ResultValidators.cpp
 )
 
 SET(PROJECT_LIBRARIES
diff --git a/src/Model/Model_ResultValidators.cpp b/src/Model/Model_ResultValidators.cpp
new file mode 100644 (file)
index 0000000..75b603f
--- /dev/null
@@ -0,0 +1,84 @@
+// File:        Model_ResultValidators.cpp
+// Created:     23 July 2014
+// Author:      Vitaly SMETANNIKOV
+
+#include "Model_ResultValidators.h"
+
+#include <ModelAPI_Result.h>
+#include <ModelAPI_Tools.h>
+#include <GeomAPI_Shape.h>
+
+#include <TopoDS_Shape.hxx>
+#include <TopoDS_Edge.hxx>
+#include <TopoDS.hxx>
+#include <BRep_Tool.hxx>
+#include <GeomAdaptor_Curve.hxx>
+
+
+ResultPtr result(const ObjectPtr theObject)
+{
+  return boost::dynamic_pointer_cast<ModelAPI_Result>(theObject);
+}
+
+TopoDS_Shape shape(ResultPtr theResult)
+{
+  boost::shared_ptr<GeomAPI_Shape> aShape = ModelAPI_Tools::shape(theResult);
+  if (aShape)
+    return aShape->impl<TopoDS_Shape>();
+  return TopoDS_Shape();
+}
+
+
+bool Model_ResultPointValidator::isValid(const ObjectPtr theObject) const
+{
+  ResultPtr aResult = result(theObject);
+  if (!aResult)
+    return false;
+  TopoDS_Shape aShape = shape(aResult);
+  if (aShape.IsNull())
+    return false;
+
+  return aShape.ShapeType() == TopAbs_VERTEX;
+}
+
+
+bool Model_ResultLineValidator::isValid(const ObjectPtr theObject) const
+{
+  ResultPtr aResult = result(theObject);
+  if (!aResult)
+    return false;
+  TopoDS_Shape aShape = shape(aResult);
+  if (aShape.IsNull())
+    return false;
+
+  if (aShape.ShapeType() == TopAbs_EDGE) {
+    TopoDS_Edge aEdge = TopoDS::Edge(aShape);
+    Standard_Real aStart, aEnd;
+    Handle(Geom_Curve) aCurve = BRep_Tool::Curve(aEdge, aStart, aEnd);
+    GeomAdaptor_Curve aAdaptor(aCurve);
+    return aAdaptor.GetType() == GeomAbs_Line;
+  }
+  return false;
+}
+
+
+bool Model_ResultArcValidator::isValid(const ObjectPtr theObject) const
+{
+  ResultPtr aResult = result(theObject);
+  if (!aResult)
+    return false;
+  TopoDS_Shape aShape = shape(aResult);
+  if (aShape.IsNull())
+    return false;
+
+  TopAbs_ShapeEnum aa = aShape.ShapeType();
+  if (aShape.ShapeType() == TopAbs_EDGE) {
+    TopoDS_Edge aEdge = TopoDS::Edge(aShape);
+    Standard_Real aStart, aEnd;
+    Handle(Geom_Curve) aCurve = BRep_Tool::Curve(aEdge, aStart, aEnd);
+    GeomAdaptor_Curve aAdaptor(aCurve);
+    return aAdaptor.GetType() == GeomAbs_Circle;
+  }
+  return false;
+}
+
diff --git a/src/Model/Model_ResultValidators.h b/src/Model/Model_ResultValidators.h
new file mode 100644 (file)
index 0000000..c76cd30
--- /dev/null
@@ -0,0 +1,30 @@
+// File:        Model_ResultValidators.h
+// Created:     23 July 2014
+// Author:      Vitaly SMETANNIKOV
+
+#ifndef Model_ResultValidators_H
+#define Model_ResultValidators_H
+
+#include "Model.h"
+#include <ModelAPI_ResultValidator.h>
+#include <ModelAPI_Object.h>
+
+class Model_ResultPointValidator: public ModelAPI_ResultValidator
+{
+public:
+  MODEL_EXPORT virtual bool isValid(const ObjectPtr theObject) const;
+};
+
+class Model_ResultLineValidator: public ModelAPI_ResultValidator
+{
+public:
+  MODEL_EXPORT virtual bool isValid(const ObjectPtr theObject) const;
+};
+
+class Model_ResultArcValidator: public ModelAPI_ResultValidator
+{
+public:
+  MODEL_EXPORT virtual bool isValid(const ObjectPtr theObject) const;
+};
+
+#endif
\ No newline at end of file
index 77af27b996ee25bf5553a321adee46dd029edf58..19e9f56dda46f684efb290f3237d36526944f6f7 100644 (file)
@@ -3,6 +3,7 @@
 // Author:      Mikhail PONIKAROV
 
 #include <Model_Validator.h>
+#include <Model_ResultValidators.h>
 #include <ModelAPI_Feature.h>
 #include <Events_Error.h>
 
@@ -90,4 +91,17 @@ void Model_ValidatorsFactory::validators(const std::string& theFeatureID,
 
 Model_ValidatorsFactory::Model_ValidatorsFactory() : ModelAPI_ValidatorsFactory()
 {
+  registerValidator("Model_ResultPointValidator", new Model_ResultPointValidator);
+  registerValidator("Model_ResultLineValidator", new Model_ResultLineValidator);
+  registerValidator("Model_ResultArcValidator", new Model_ResultArcValidator);
 }
+
+
+const ModelAPI_Validator* Model_ValidatorsFactory::validator(const std::string& theID) const
+{
+  std::map<std::string, ModelAPI_Validator*>::const_iterator aIt = myIDs.find(theID);
+  if (aIt != myIDs.end()) {
+    return aIt->second;
+  }
+  return NULL;
+}
\ No newline at end of file
index f1cfe24fce493792fbbd7fa3bbebb9b5f5255e73..45ad05c14f8535e5275380d803f6f1b91685d4b8 100644 (file)
@@ -55,6 +55,9 @@ public:
     std::list<ModelAPI_Validator*>& theValidators, 
     std::list<std::list<std::string> >& theArguments) const;
 
+  /// Returns registered validator by its Id
+  virtual const ModelAPI_Validator* validator(const std::string& theID) const;
+
   /// Returns the result of "validate" method for attribute of validator.
   /// If validator is not exists, returns true: everything is valid by default.
   //MODEL_EXPORT virtual bool validate(
index 4d10c9ce172da4f4ba642c8bd539cc7948e124e8..cc1596c0fb89a4670c01bcbd69f917ccc0e45417 100644 (file)
@@ -26,11 +26,15 @@ SET(PROJECT_HEADERS
     ModelAPI_ResultConstruction.h
     ModelAPI_ResultPart.h
     ModelAPI_ResultParameters.h
+       ModelAPI_ResultValidator.h
+       ModelAPI_AttributeValidator.h
+       ModelAPI_Tools.h
 )
 
 SET(PROJECT_SOURCES
     ModelAPI_Feature.cpp
     ModelAPI_PluginManager.cpp
+       ModelAPI_Tools.cpp
 )
 
 SET(PROJECT_LIBRARIES
diff --git a/src/ModelAPI/ModelAPI_AttributeValidator.h b/src/ModelAPI/ModelAPI_AttributeValidator.h
new file mode 100644 (file)
index 0000000..b40c145
--- /dev/null
@@ -0,0 +1,21 @@
+// File:        ModelAPI_AttributeValidator.h
+// Created:     5 Aug 2014
+// Author:      Vitaly SMETANNIKOV
+
+#ifndef ModelAPI_AttributeValidator_H
+#define ModelAPI_AttributeValidator_H
+
+#include <ModelAPI_Feature.h>
+#include <ModelAPI_Object.h>
+#include <ModelAPI_Validator.h>
+
+
+class ModelAPI_AttributeValidator: public ModelAPI_Validator
+{
+public:
+  virtual bool isValid(const FeaturePtr& theFeature, 
+                       const std::list<std::string>& theArguments,
+                       const ObjectPtr& theObject) const = 0;
+};
+
+#endif
index 5617cedd9a9fffdb5747edd7b6269a688dd0309d..028f17385affbd04b928466274a9ee08cb5d904b 100644 (file)
@@ -5,6 +5,7 @@
 #include "ModelAPI_Feature.h"
 #include <ModelAPI_Events.h>
 #include <ModelAPI_Result.h>
+#include <ModelAPI_Document.h>
 #include <Events_Loop.h>
 
 const std::list<boost::shared_ptr<ModelAPI_Result> >& ModelAPI_Feature::results() 
@@ -70,3 +71,16 @@ ModelAPI_Feature::~ModelAPI_Feature()
     ModelAPI_EventCreator::get()->sendDeleted(aRes->document(), aRes->groupName());
   }
 }
+
+FeaturePtr ModelAPI_Feature::feature(ObjectPtr theObject)
+{
+  FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(theObject);
+  if (!aFeature) {
+    ResultPtr aResult = boost::dynamic_pointer_cast<ModelAPI_Result>(theObject);
+    if (aResult) {
+      DocumentPtr aDoc = aResult->document();
+      return aDoc->feature(aResult);
+    }
+  }
+  return aFeature;
+}
index b42266074ba9bb3a2e54e2a015194de812a8539f..a1d048af378b7ef274a7ee1b3109eb45b57ee20f 100644 (file)
@@ -62,6 +62,9 @@ public:
 
   /// To virtually destroy the fields of successors
   MODELAPI_EXPORT virtual ~ModelAPI_Feature();
+
+  MODELAPI_EXPORT static boost::shared_ptr<ModelAPI_Feature> feature(ObjectPtr theObject);
+
 };
 
 //! Pointer on feature object
diff --git a/src/ModelAPI/ModelAPI_ResultValidator.h b/src/ModelAPI/ModelAPI_ResultValidator.h
new file mode 100644 (file)
index 0000000..7484246
--- /dev/null
@@ -0,0 +1,18 @@
+// File:        ModelAPI_ResultValidators.h
+// Created:     23 July 2014
+// Author:      Vitaly SMETANNIKOV
+
+#ifndef ModelAPI_ResultValidators_H
+#define ModelAPI_ResultValidators_H
+
+#include "ModelAPI_Validator.h"
+#include "ModelAPI_Object.h"
+
+class ModelAPI_ResultValidator: public ModelAPI_Validator
+{
+public:
+  virtual bool isValid(const ObjectPtr theObject) const = 0;
+};
+
+
+#endif
\ No newline at end of file
diff --git a/src/ModelAPI/ModelAPI_Tools.cpp b/src/ModelAPI/ModelAPI_Tools.cpp
new file mode 100644 (file)
index 0000000..1c49c67
--- /dev/null
@@ -0,0 +1,21 @@
+// File:        ModelAPI_Tools.cpp
+// Created:     06 Aug 2014
+// Author:      Vitaly Smetannikov
+
+#include "ModelAPI_Tools.h"
+#include <ModelAPI_ResultBody.h>
+#include <ModelAPI_ResultConstruction.h>
+
+
+namespace ModelAPI_Tools {
+
+boost::shared_ptr<GeomAPI_Shape> shape(const ResultPtr& theResult)
+{
+  ResultBodyPtr aBody = boost::dynamic_pointer_cast<ModelAPI_ResultBody>(theResult);
+  if (aBody) return aBody->shape();
+  ResultConstructionPtr aConstruct = boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(theResult);
+  if (aConstruct) return aConstruct->shape();
+  return boost::shared_ptr<GeomAPI_Shape>();
+}
+
+}
\ No newline at end of file
diff --git a/src/ModelAPI/ModelAPI_Tools.h b/src/ModelAPI/ModelAPI_Tools.h
new file mode 100644 (file)
index 0000000..f4fc0eb
--- /dev/null
@@ -0,0 +1,18 @@
+// File:        ModelAPI_Tools.h
+// Created:     06 Aug 2014
+// Author:      Vitaly Smetannikov
+
+#ifndef ModelAPI_Tools_HeaderFile
+#define ModelAPI_Tools_HeaderFile
+
+#include "ModelAPI.h"
+#include <ModelAPI_Result.h>
+#include <GeomAPI_Shape.h>
+
+namespace ModelAPI_Tools 
+{
+  /// Returns shape from the given Result object
+  MODELAPI_EXPORT boost::shared_ptr<GeomAPI_Shape> shape(const ResultPtr& theResult);
+};
+
+#endif
\ No newline at end of file
index 4f17e634c99eafb237fd2ff7da3c983c48c7464a..88ab1574c31b7f49142df8c8b6783eb078555e1f 100644 (file)
@@ -73,6 +73,9 @@ public:
     std::list<ModelAPI_Validator*>& theValidators, 
     std::list<std::list<std::string> >& theArguments) const = 0;
 
+  /// Returns registered validator by its Id
+  virtual const ModelAPI_Validator* validator(const std::string& theID) const = 0;
+
   /// Returns the result of "validate" method for attribute of validator.
   /// If validator is not exists, returns true: everything is valid by default.
   //virtual bool validate(
index 4c3f20caa061d34b52ef2da5d2f053d3561eeab4..b21756a5c39ff3dc9c72c13d5cbfd6696a9308cc 100644 (file)
@@ -25,9 +25,6 @@ SET(PROJECT_HEADERS
        ModuleBase_SelectionValidator.h
        ModuleBase_ISelection.h
        ModuleBase_ViewerPrs.h
-       ModuleBase_Tools.h
-       ModuleBase_ResultValidators.h
-       ModuleBase_FeatureValidator.h
 )
 
 SET(PROJECT_SOURCES
@@ -47,8 +44,6 @@ SET(PROJECT_SOURCES
        ModuleBase_WidgetPoint2dDistance.cpp
        ModuleBase_WidgetValue.cpp
        ModuleBase_WidgetValueFeature.cpp
-       ModuleBase_Tools.cpp
-       ModuleBase_ResultValidators.cpp
 )
 
 SET(PROJECT_LIBRARIES
diff --git a/src/ModuleBase/ModuleBase_FeatureValidator.h b/src/ModuleBase/ModuleBase_FeatureValidator.h
deleted file mode 100644 (file)
index ccbcca6..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-// File:        ModuleBase_FeatureValidator.h
-// Created:     8 Jul 2014
-// Author:      Vitaly SMETANNIKOV
-
-#ifndef ModuleBase_FeatureValidator_H
-#define ModuleBase_FeatureValidator_H
-
-#include "ModuleBase.h"
-
-#include <ModelAPI_Feature.h>
-#include <ModelAPI_Validator.h>
-
-
-class ModuleBase_FeatureValidator: public ModelAPI_Validator
-{
-public:
-  virtual bool isValid(const FeaturePtr theFeature) const = 0;
-};
-
-#endif
index de0548b3d355b5ba765768d324f2015c4c32c548..c150d01b3c0fdb1c4dac49e21fcf510bf65724d7 100644 (file)
@@ -14,7 +14,6 @@
 #include <boost/shared_ptr.hpp>
 
 class Config_WidgetAPI;
-class ModelAPI_Feature;
 class ModuleBase_WidgetValue;
 class QKeyEvent;
 
@@ -49,9 +48,9 @@ public:
 
   /// Saves the internal parameters to the given feature
   /// \param theObject a model feature to be changed
-  virtual bool storeValue(ObjectPtr theObject) const = 0;
+  virtual bool storeValue() const = 0;
 
-  virtual bool restoreValue(ObjectPtr theObject) = 0;
+  virtual bool restoreValue() = 0;
 
   /// Set focus to the first control of the current widget. The focus policy of the control is checked.
   /// If the widget has the NonFocus focus policy, it is skipped.
@@ -74,6 +73,9 @@ public:
   /// \returns the string value
   std::string parentID() const { return myParentId; }
 
+  FeaturePtr feature() const { return myFeature;}
+  void setFeature(const FeaturePtr& theFeature) { myFeature = theFeature; }
+
 signals:
   /// The signal about widget values changed
   void valuesChanged();
@@ -94,9 +96,10 @@ protected:
 
   bool myHasDefaultValue; /// the boolean state whether the control has a default value
 
-private:
+
   std::string myAttributeID; /// the attribute name of the model feature
   std::string myParentId;    /// name of parent
+  FeaturePtr myFeature;
 };
 
 #endif
index 44eddb349c00e32ab19c6419dbc51a5c4d797699..4a980a1dc2b8b0dc534ca40968f0b57ca247bc57 100644 (file)
@@ -9,7 +9,6 @@
 
 #include "ModuleBase_OperationDescription.h"
 #include "ModuleBase_ModelWidget.h"
-#include "ModuleBase_FeatureValidator.h"
 
 #include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_Document.h>
@@ -62,7 +61,7 @@ void ModuleBase_Operation::storeCustomValue()
 
   ModuleBase_ModelWidget* aCustom = dynamic_cast<ModuleBase_ModelWidget*>(sender());
   if (aCustom)
-    aCustom->storeValue(myFeature);
+    aCustom->storeValue();
 }
 
 void ModuleBase_Operation::onWidgetActivated(ModuleBase_ModelWidget* theWidget)
@@ -97,7 +96,7 @@ void ModuleBase_Operation::afterCommitOperation()
 bool ModuleBase_Operation::canBeCommitted() const
 {
   if (ModuleBase_IOperation::canBeCommitted()) {
-    FeaturePtr aFeature = feature();
+/*    FeaturePtr aFeature = feature();
     std::string aId = aFeature->getKind();
 
     PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
@@ -112,7 +111,7 @@ bool ModuleBase_Operation::canBeCommitted() const
         if (!aFValidator->isValid(aFeature))
           return false;
       }
-    }
+    }*/
     return true;
   }
   return false;
index 7da2d12ad95cc3245ee26386559153956893370d..87f636360229b6e5d2d68ee3fa910042cb5d957d 100644 (file)
@@ -11,27 +11,6 @@ namespace ModuleBase_Tools
 {
 
 //******************************************************************
-boost::shared_ptr<GeomAPI_Shape> shape(ResultPtr theResult)
-{
-  ResultBodyPtr aBody = boost::dynamic_pointer_cast<ModelAPI_ResultBody>(theResult);
-  if (aBody) return aBody->shape();
-  ResultConstructionPtr aConstruct = boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(theResult);
-  if (aConstruct) return aConstruct->shape();
-  return boost::shared_ptr<GeomAPI_Shape>();
-}
 
 //******************************************************************
-FeaturePtr feature(ObjectPtr theObject)
-{
-  FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(theObject);
-  if (!aFeature) {
-    ResultPtr aResult = boost::dynamic_pointer_cast<ModelAPI_Result>(theObject);
-    if (aResult) {
-      DocumentPtr aDoc = aResult->document();
-      return aDoc->feature(aResult);
-    }
-  }
-  return aFeature;
-}
-
 }
index c77ecad44d99958e7f43cefb0a60f55b9eeadf81..07a8eb000a427539c9211f89b706e448da4e4f7d 100644 (file)
@@ -42,21 +42,21 @@ QWidget* ModuleBase_WidgetBoolValue::getControl() const
   return myCheckBox; 
 }
 
-bool ModuleBase_WidgetBoolValue::storeValue(ObjectPtr theObject) const
+bool ModuleBase_WidgetBoolValue::storeValue() const
 {
-  DataPtr aData = theObject->data();
+  DataPtr aData = myFeature->data();
   boost::shared_ptr<ModelAPI_AttributeBoolean> aBool = aData->boolean(attributeID());
 
   if (aBool->value() != myCheckBox->isChecked()) {
     aBool->setValue(myCheckBox->isChecked());
-    updateObject(theObject);
+    updateObject(myFeature);
   }
   return true;
 }
 
-bool ModuleBase_WidgetBoolValue::restoreValue(ObjectPtr theObject)
+bool ModuleBase_WidgetBoolValue::restoreValue()
 {
-  DataPtr aData = theObject->data();
+  DataPtr aData = myFeature->data();
   boost::shared_ptr<ModelAPI_AttributeBoolean> aRef = aData->boolean(attributeID());
 
   bool isBlocked = myCheckBox->blockSignals(true);
index 17c5a68498b1bdec2e02b237216c4acb040a980c..7f6c822a87d3e1d943e0e178cd615130d3920597 100644 (file)
@@ -25,9 +25,9 @@ public:
 
   /// Saves the internal parameters to the given feature
   /// \param theObject a model feature to be changed
-  virtual bool storeValue(ObjectPtr theObject) const;
+  virtual bool storeValue() const;
 
-  virtual bool restoreValue(ObjectPtr theObject);
+  virtual bool restoreValue();
 
   /// Returns list of widget controls
   /// \return a control list
index 97782bf745f66a89bcdf735736456c33948d1c9f..beb384bcdfa5b7b21f8e45445a307c88a1cae49a 100644 (file)
@@ -90,20 +90,20 @@ ModuleBase_WidgetDoubleValue::~ModuleBase_WidgetDoubleValue()
 {
 }
 
-bool ModuleBase_WidgetDoubleValue::storeValue(ObjectPtr theObject) const
+bool ModuleBase_WidgetDoubleValue::storeValue() const
 {
-  DataPtr aData = theObject->data();
+  DataPtr aData = myFeature->data();
   AttributeDoublePtr aReal = aData->real(attributeID());
   if (aReal->value() != mySpinBox->value()) {
     aReal->setValue(mySpinBox->value());
-    updateObject(theObject);
+    updateObject(myFeature);
   }
   return true;
 }
 
-bool ModuleBase_WidgetDoubleValue::restoreValue(ObjectPtr theObject)
+bool ModuleBase_WidgetDoubleValue::restoreValue()
 {
-  DataPtr aData = theObject->data();
+  DataPtr aData = myFeature->data();
   AttributeDoublePtr aRef = aData->real(attributeID());
 
   bool isBlocked = mySpinBox->blockSignals(true);
index a04a4e928fa804b2a349d1548b3280cd6a68df3c..15b9063b3552acb4dd135c44f61d93fa6dbf6268 100644 (file)
@@ -26,9 +26,9 @@ public:
 
   /// Saves the internal parameters to the given feature
   /// \param theObject a model feature to be changed
-  virtual bool storeValue(ObjectPtr theObject) const;
+  virtual bool storeValue() const;
 
-  virtual bool restoreValue(ObjectPtr theObject);
+  virtual bool restoreValue();
 
   /// Returns list of widget controls
   /// \return a control list
index 47e9960be06285ea6e882961c283926b1011b5d8..983329b53ddf61b42dae50d72e1ad5bc23e0e2a2 100644 (file)
@@ -6,20 +6,20 @@
 
 #include <ModuleBase_WidgetValueFeature.h>
 #include <ModuleBase_WidgetValue.h>
-#include <ModuleBase_ResultValidators.h>
-#include <ModuleBase_Tools.h>
 
 #include <Config_Keywords.h>
 #include <Config_WidgetAPI.h>
 
 #include <Events_Loop.h>
-#include <ModelAPI_Events.h>
 
+#include <ModelAPI_Events.h>
 #include <ModelAPI_Feature.h>
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Object.h>
 #include <ModelAPI_AttributeRefAttr.h>
 #include <ModelAPI_Validator.h>
+#include <ModelAPI_ResultValidator.h>
+#include <ModelAPI_AttributeValidator.h>
 
 #include <QWidget>
 #include <QLineEdit>
@@ -31,10 +31,6 @@ ModuleBase_WidgetFeature::ModuleBase_WidgetFeature(QWidget* theParent,
                                                    const std::string& theParentId)
 : ModuleBase_ModelWidget(theParent, theData, theParentId)
 {
-  //QString aKinds = QString::fromStdString(theData->getProperty(FEATURE_KEYSEQUENCE));
-  //myObjectKinds = aKinds.split(" ");
-  //theData->
-
   myContainer = new QWidget(theParent);
   QHBoxLayout* aControlLay = new QHBoxLayout(myContainer);
   aControlLay->setContentsMargins(0, 0, 0, 0);
@@ -80,11 +76,13 @@ bool ModuleBase_WidgetFeature::setObject(const ObjectPtr& theObject, bool theSen
   std::list<ModelAPI_Validator*> aValidators;
   std::list<std::list<std::string> > anArguments;
   aFactory->validators(parentID(), attributeID(), aValidators, anArguments);
+
+  // Check the type of selected object
   std::list<ModelAPI_Validator*>::iterator aValidator = aValidators.begin();
   bool isValid = true;
   for(; aValidator != aValidators.end(); aValidator++) {
-    const ModuleBase_ResultValidator* aResValidator = 
-      dynamic_cast<const ModuleBase_ResultValidator*>(*aValidator);
+    const ModelAPI_ResultValidator* aResValidator = 
+      dynamic_cast<const ModelAPI_ResultValidator*>(*aValidator);
     if (aResValidator) {
       isValid = false;
       if (aResValidator->isValid(theObject)) {
@@ -96,35 +94,49 @@ bool ModuleBase_WidgetFeature::setObject(const ObjectPtr& theObject, bool theSen
   if (!isValid)
     return false;
 
-  myObject = ModuleBase_Tools::feature(theObject);
+  // Check the acceptability of the object as attribute
+  aValidator = aValidators.begin();
+  std::list<std::list<std::string> >::iterator aArgs = anArguments.begin();
+  for(; aValidator != aValidators.end(); aValidator++, aArgs++) {
+    const ModelAPI_AttributeValidator* aAttrValidator = 
+      dynamic_cast<const ModelAPI_AttributeValidator*>(*aValidator);
+    if (aAttrValidator) {
+      if (!aAttrValidator->isValid(myFeature, *aArgs, theObject)) {
+        return false;
+      }
+    }
+  }
+
+  myObject = theObject;
   myEditor->setText(theObject ? theObject->data()->name().c_str() : "");
   if (theSendEvent)
     emit valuesChanged();
   return true;
 }
 
-bool ModuleBase_WidgetFeature::storeValue(ObjectPtr theObject) const
+bool ModuleBase_WidgetFeature::storeValue() const
 {
-  FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(theObject);
-  if (!aFeature)
-    return false;
-  boost::shared_ptr<ModelAPI_Data> aData = aFeature->data();
+  //FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(theObject);
+  //if (!aFeature)
+  //  return false;
+  boost::shared_ptr<ModelAPI_Data> aData = myFeature->data();
   boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
           boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(attributeID()));
 
   ModuleBase_WidgetFeature* that = (ModuleBase_WidgetFeature*) this;
   aRef->setObject(myObject);
-  aFeature->execute();
-  updateObject(theObject);
+  myFeature->execute();
+  updateObject(myFeature);
   return true;
 }
 
-bool ModuleBase_WidgetFeature::restoreValue(ObjectPtr theObject)
+bool ModuleBase_WidgetFeature::restoreValue()
 {
-  boost::shared_ptr<ModelAPI_Data> aData = theObject->data();
+  boost::shared_ptr<ModelAPI_Data> aData = myFeature->data();
   boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
           boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(attributeID()));
 
+  ObjectPtr aObj = aRef->object();
   FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(aRef->object());
   if (aFeature) {
     myObject = aFeature;
index 81720edabf1400a45892d4f0e3b5c821fa225a1c..fee570d64f78553c08cbda9ab64b91ddc0150cf3 100644 (file)
@@ -40,9 +40,9 @@ public:
 
   /// Saves the internal parameters to the given feature
   /// \param theFeature a model feature to be changed
-  virtual bool storeValue(ObjectPtr theObject) const;
+  virtual bool storeValue() const;
 
-  virtual bool restoreValue(ObjectPtr theObject);
+  virtual bool restoreValue();
 
   /// Returns the internal parent wiget control, that can be shown anywhere
   /// \returns the widget
index 525d243566f882b6332a6049438094b145b188fd..40fb3a52f7bae73bd9c2ce01e3de5dcbb4b2ed85 100644 (file)
@@ -6,7 +6,6 @@
 
 #include <ModuleBase_WidgetValueFeature.h>
 #include <ModuleBase_WidgetValue.h>
-#include <ModuleBase_Tools.h>
 
 #include <Config_Keywords.h>
 #include <Config_WidgetAPI.h>
@@ -18,6 +17,8 @@
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Object.h>
 #include <ModelAPI_AttributeRefAttr.h>
+#include <ModelAPI_Validator.h>
+
 #include <GeomAPI_Pnt2d.h>
 
 #include <GeomDataAPI_Point2D.h>
@@ -54,7 +55,7 @@ bool ModuleBase_WidgetFeatureOrAttribute::setValue(ModuleBase_WidgetValue* theVa
         isDone = setObject(aObject, false);
       }
       if (aValuePoint) {
-        FeaturePtr aFeature = ModuleBase_Tools::feature(aObject);
+        FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
         if (aFeature) {
           // find the given point in the feature attributes
           std::list<boost::shared_ptr<ModelAPI_Attribute> > anAttiributes =
@@ -79,13 +80,13 @@ bool ModuleBase_WidgetFeatureOrAttribute::setValue(ModuleBase_WidgetValue* theVa
   return isDone;
 }
 
-bool ModuleBase_WidgetFeatureOrAttribute::storeValue(ObjectPtr theFeature) const
+bool ModuleBase_WidgetFeatureOrAttribute::storeValue() const
 {
-  FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(theFeature);
-  if (!aFeature)
-    return false;
+  //FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(theFeature);
+  //if (!aFeature)
+  //  return false;
 
-  boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
+  boost::shared_ptr<ModelAPI_Data> aData = myFeature->data();
   boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
           boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(attributeID()));
 
@@ -94,19 +95,20 @@ bool ModuleBase_WidgetFeatureOrAttribute::storeValue(ObjectPtr theFeature) const
   if (myAttribute)
     aRef->setAttr(myAttribute);
 
-  aFeature->execute();
-  updateObject(theFeature);
+  myFeature->execute();
+  updateObject(myFeature);
 
   return true;
 }
 
-bool ModuleBase_WidgetFeatureOrAttribute::restoreValue(ObjectPtr theFeature)
+bool ModuleBase_WidgetFeatureOrAttribute::restoreValue()
 {
-  boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
+  boost::shared_ptr<ModelAPI_Data> aData = myFeature->data();
   boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
           boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(attributeID()));
 
-  FeaturePtr aFeature = ModuleBase_Tools::feature(aRef->object());
+  ObjectPtr aObj = aRef->object();
+  FeaturePtr aFeature = ModelAPI_Feature::feature(aRef->object());
   if (aFeature) {
     myObject = aFeature;
     myAttribute = aRef->attr();
index 9de6c149a36fcedffb068fbb14cfc164fe394867..0518409bd1198d69545d8adedcdf0a27fe33d01a 100644 (file)
@@ -36,9 +36,9 @@ public:
 
   /// Saves the internal parameters to the given feature
   /// \param theFeature a model feature to be changed
-  virtual bool storeValue(ObjectPtr theFeature) const;
+  virtual bool storeValue() const;
 
-  virtual bool restoreValue(ObjectPtr theFeature);
+  virtual bool restoreValue();
 
 protected:
   /// Set the attribute
index c9c3dd9c77bd4076df0a037ffd4b3827dc648ca2..cd88c57b7d188e7f1ff5514b2437681db93b62f1 100644 (file)
@@ -102,24 +102,24 @@ void ModuleBase_WidgetPoint2D::setPoint(const boost::shared_ptr<GeomAPI_Pnt2d>&
   emit valuesChanged();
 }
 
-bool ModuleBase_WidgetPoint2D::storeValue(ObjectPtr theObject) const
+bool ModuleBase_WidgetPoint2D::storeValue() const
 {
-  boost::shared_ptr<ModelAPI_Data> aData = theObject->data();
+  boost::shared_ptr<ModelAPI_Data> aData = myFeature->data();
   boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
     boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(attributeID()));
 
   ModuleBase_WidgetPoint2D* that = (ModuleBase_WidgetPoint2D*) this;
   bool isBlocked = that->blockSignals(true);
   aPoint->setValue(myXSpin->value(), myYSpin->value());
-  updateObject(theObject);
+  updateObject(myFeature);
   that->blockSignals(isBlocked);
 
   return true;
 }
 
-bool ModuleBase_WidgetPoint2D::restoreValue(ObjectPtr theObject)
+bool ModuleBase_WidgetPoint2D::restoreValue()
 {
-  boost::shared_ptr<ModelAPI_Data> aData = theObject->data();
+  boost::shared_ptr<ModelAPI_Data> aData = myFeature->data();
   boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
     boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(attributeID()));
 
index ed249c4b76feae800cb8929fc53f99a2a6b7220c..77fbd74eee380035412274465eab65596b922668 100644 (file)
@@ -40,9 +40,9 @@ public:
 
   /// Saves the internal parameters to the given feature
   /// \param theObject a model feature to be changed
-  virtual bool storeValue(ObjectPtr theObject) const;
+  virtual bool storeValue() const;
 
-  virtual bool restoreValue(ObjectPtr theObject);
+  virtual bool restoreValue();
 
   /// Returns the internal parent wiget control, that can be shown anywhere
   /// \returns the widget
index 8cb33574b8183bb175950ce4303c7c2b230a9c11..c0933f566f361fd97bf3dd3ab1fdf277da4b0be1 100644 (file)
@@ -5,10 +5,10 @@
 
 #include "ModuleBase_WidgetSelector.h"
 #include "ModuleBase_IWorkshop.h"
-#include "ModuleBase_Tools.h"
 
 #include <Events_Loop.h>
 #include <ModelAPI_Events.h>
+#include <ModelAPI_Tools.h>
 
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Object.h>
@@ -102,28 +102,28 @@ ModuleBase_WidgetSelector::~ModuleBase_WidgetSelector()
 }
 
 //********************************************************************
-bool ModuleBase_WidgetSelector::storeValue(ObjectPtr theObject) const
+bool ModuleBase_WidgetSelector::storeValue() const
 {
-  FeaturePtr aSelectedFeature = ModuleBase_Tools::feature(mySelectedObject);
-  if (aSelectedFeature == theObject) // In order to avoid selection of the same object
+  FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(mySelectedObject);
+  if (aSelectedFeature == myFeature) // In order to avoid selection of the same object
     return false;
 
-  DataPtr aData = theObject->data();
+  DataPtr aData = myFeature->data();
   boost::shared_ptr<ModelAPI_AttributeReference> aRef = 
     boost::dynamic_pointer_cast<ModelAPI_AttributeReference>(aData->attribute(attributeID()));
 
   ObjectPtr aObject = aRef->value();
   if (!(aObject && aObject->isSame(mySelectedObject))) {
     aRef->setValue(mySelectedObject);
-    updateObject(theObject);
+    updateObject(myFeature);
   }
   return true;
 }
 
 //********************************************************************
-bool ModuleBase_WidgetSelector::restoreValue(ObjectPtr theObject)
+bool ModuleBase_WidgetSelector::restoreValue()
 {
-  DataPtr aData = theObject->data();
+  DataPtr aData = myFeature->data();
   boost::shared_ptr<ModelAPI_AttributeReference> aRef = aData->reference(attributeID());
 
   bool isBlocked = this->blockSignals(true);
@@ -174,7 +174,7 @@ void ModuleBase_WidgetSelector::onSelectionChanged()
 bool ModuleBase_WidgetSelector::isAccepted(const ObjectPtr theResult) const
 {
   ResultPtr aResult = boost::dynamic_pointer_cast<ModelAPI_Result>(theResult);
-  boost::shared_ptr<GeomAPI_Shape> aShapePtr = ModuleBase_Tools::shape(aResult);
+  boost::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
   if (!aShapePtr) return false;
   TopoDS_Shape aShape = aShapePtr->impl<TopoDS_Shape>();
   if (aShape.IsNull()) return false;
index 1388bc77317fcc2addf1cad120bd7a155d46e719..9d71808489b8c119c753dddea333381ba0c3cda5 100644 (file)
@@ -34,9 +34,9 @@ public:
 
   /// Saves the internal parameters to the given feature
   /// \param theObject a model feature to be changed
-  virtual bool storeValue(ObjectPtr theObject) const;
+  virtual bool storeValue() const;
 
-  virtual bool restoreValue(ObjectPtr theObject);
+  virtual bool restoreValue();
 
   /// Returns the internal parent wiget control, that can be shown anywhere
   /// \returns the widget
index 160f63f2e91fd12c40f3f45dcf8dd07492b03eb3..ecace8c289d143877dfa5ecdb727440f69afaa8d 100644 (file)
@@ -13,7 +13,6 @@
 #include <ModuleBase_OperationDescription.h>
 #include <ModuleBase_WidgetFactory.h>
 #include <ModuleBase_Operation.h>
-#include <ModuleBase_Tools.h>
 
 #include <ModelAPI_Object.h>
 #include <ModelAPI_Events.h>
@@ -288,7 +287,7 @@ void PartSet_Module::onFitAllView()
 
 void PartSet_Module::onLaunchOperation(std::string theName, ObjectPtr theObject)
 {
-  FeaturePtr aFeature = ModuleBase_Tools::feature(theObject);
+  FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
   if (!aFeature) {
     qDebug("Warning! Restart operation without feature!");
     return;
index 32f0a86e2f2de97dd6fc01cbb00c7a1e8ee3657d..887ec4f9ce8cf51a6afa43e3dfa1a214a9db16ab 100644 (file)
 #include <ModuleBase_OperationDescription.h>
 #include <ModuleBase_WidgetEditor.h>
 #include <ModuleBase_ViewerPrs.h>
-#include <ModuleBase_Tools.h>
 
 #include <ModelAPI_Events.h>
 
 #include <SketchPlugin_Feature.h>
 #include <GeomDataAPI_Point2D.h>
+
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Document.h>
-
 #include <ModelAPI_Events.h>
 
 #include <Events_Loop.h>
@@ -80,7 +79,7 @@ void PartSet_OperationFeatureEdit::mousePressed(QMouseEvent* theEvent, Handle(V3
   if (!aObject && !theSelected.empty()) // changed for a constrain
     aObject = theSelected.front().object();
 
-  FeaturePtr aFeature = ModuleBase_Tools::feature(aObject);
+  FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
   if (!aFeature || aFeature != feature()) {
     if (commit()) {
       emit featureConstructed(feature(), FM_Deactivation);
index 30796c5fbc75228ce98eba176ad58da85e03a3d1..83d2a04b5f6dc4d705b0956bc5423d9347fb1a43 100644 (file)
@@ -8,7 +8,6 @@
 
 #include <ModuleBase_OperationDescription.h>
 #include <ModuleBase_ViewerPrs.h>
-#include <ModuleBase_Tools.h>
 
 #include <ModelAPI_Events.h>
 
@@ -60,7 +59,7 @@ void PartSet_OperationFeatureEditMulti::initSelection(const std::list<ModuleBase
     bool isSelected = false;
     std::list<ModuleBase_ViewerPrs>::const_iterator anIt = theSelected.begin(), aLast = theSelected.end();
     for (; anIt != aLast && !isSelected; anIt++) {
-      isSelected = ModuleBase_Tools::feature((*anIt).object()) == feature();
+      isSelected = ModelAPI_Feature::feature((*anIt).object()) == feature();
     }
     if (!isSelected)
       myFeatures = theHighlighted;
@@ -114,7 +113,7 @@ void PartSet_OperationFeatureEditMulti::mouseMoved(QMouseEvent* theEvent, Handle
       ObjectPtr aObject = (*anIt).object();
       if (!aObject || aObject == feature())
         continue;
-      FeaturePtr aFeature = ModuleBase_Tools::feature(aObject);
+      FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
       if (aFeature) {
         aSketchFeature = boost::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
         if (aSketchFeature)
index 558747b46864da25f2bb5eb7dec59e0ce730a964..98cae8a48fe9d50ec7a38244e88e6c00d3d2e272 100644 (file)
@@ -25,9 +25,9 @@ public:
 
   /// Saves the internal parameters to the given feature
   /// \param theFeature a model feature to be changed
-  virtual bool storeValue(ObjectPtr theFeature) const { return true;}
+  virtual bool storeValue() const { return true;}
 
-  virtual bool restoreValue(ObjectPtr theFeature) { return true;}
+  virtual bool restoreValue() { return true;}
 
   /// Returns list of widget controls
   /// \return a control list
index c731f49ea53f801f43036abb251fe724fe5b8f33..d45087849ec89f9a252aea30cab8d64549fd5808 100644 (file)
@@ -57,7 +57,6 @@ INCLUDE_DIRECTORIES(
   ../GeomAPI
   ../GeomAlgoAPI
   ../GeomDataAPI
-  ../ModuleBase
 )
 
 INSTALL(TARGETS SketchPlugin DESTINATION plugins)
index 531f09bd6a9fcd1cfdbad02fd3137c9281fad2e5..de504f56ea4b1ca99cc88607c51d4dba6df46f09 100644 (file)
 #include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_Data.h>
 
-/// Obtain the point object from specified constraint parameter
-static boost::shared_ptr<GeomDataAPI_Point2D> getFeaturePoint(
-            DataPtr             theData,
-            const std::string&  theAttribute);
-
-static boost::shared_ptr<SketchPlugin_Line> getFeatureLine(DataPtr theData, const std::string& theAttribute);
-
-static boost::shared_ptr<GeomAPI_Pnt2d> getProjectionPoint(const boost::shared_ptr<SketchPlugin_Line>& theLine, 
-                                                           const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint);
-
 
 SketchPlugin_ConstraintDistance::SketchPlugin_ConstraintDistance()
 {
@@ -153,7 +143,7 @@ boost::shared_ptr<GeomDataAPI_Point2D> getFeaturePoint(DataPtr theData,
   boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = 
     boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theData->attribute(theAttribute));
   if (anAttr)
-    aFeature = SketchPlugin_Sketch::getFeature(anAttr->object());
+    aFeature = ModelAPI_Feature::feature(anAttr->object());
 
   if (aFeature && aFeature->getKind() == SketchPlugin_Point::ID())
     aPointAttr = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
@@ -177,7 +167,7 @@ boost::shared_ptr<SketchPlugin_Line> getFeatureLine(DataPtr theData, const std::
   boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = 
     boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theData->attribute(theAttribute));
   if (anAttr) {
-    FeaturePtr aFeature = SketchPlugin_Sketch::getFeature(anAttr->object());
+    FeaturePtr aFeature = ModelAPI_Feature::feature(anAttr->object());
     if (aFeature && aFeature->getKind() == SketchPlugin_Line::ID()) {
       aLine = boost::dynamic_pointer_cast<SketchPlugin_Line>(aFeature);
     }
index 3aed4ba9e0fa50600719afe9ca09561005ca458a..6a229544dd5d82395983afcbb578e7cbe7ce9001 100644 (file)
@@ -8,9 +8,13 @@
 #include "SketchPlugin.h"
 #include "SketchPlugin_Constraint.h"
 #include "SketchPlugin_Sketch.h"
+#include "ModelAPI_Data.h"
 
 #include <list>
 
+class SketchPlugin_Line;
+class GeomDataAPI_Point2D;
+
 /** \class SketchPlugin_ConstraintDistance
  *  \ingroup DataModel
  *  \brief Feature for creation of a new constraint which defines a distance
@@ -52,4 +56,15 @@ public:
   SketchPlugin_ConstraintDistance();
 };
 
+
+/// Obtain the point object from specified constraint parameter
+boost::shared_ptr<GeomDataAPI_Point2D> getFeaturePoint(DataPtr theData,
+                                                       const std::string&  theAttribute);
+
+boost::shared_ptr<SketchPlugin_Line> getFeatureLine(DataPtr theData, const std::string& theAttribute);
+
+boost::shared_ptr<GeomAPI_Pnt2d> getProjectionPoint(const boost::shared_ptr<SketchPlugin_Line>& theLine, 
+                                                    const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint);
+
+
 #endif
index 3c2b146b82be40b3e5b6e7552e4295381bcb980a..28d2cf7d35b2b63dac6e836e0520cbb945efef88 100644 (file)
@@ -36,7 +36,7 @@ void SketchPlugin_ConstraintLength::execute()
 
     boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
       boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(data()->attribute(SketchPlugin_Constraint::ENTITY_A()));
-    FeaturePtr aFeature = SketchPlugin_Sketch::getFeature(aRef->object());
+    FeaturePtr aFeature = ModelAPI_Feature::feature(aRef->object());
     if (aFeature) {
       // set length value
       boost::shared_ptr<GeomDataAPI_Point2D> aPoint1 =
@@ -65,7 +65,7 @@ boost::shared_ptr<GeomAPI_AISObject> SketchPlugin_ConstraintLength::getAISObject
     boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(data()->attribute(SketchPlugin_Constraint::ENTITY_A()));
   if (!anAttr)
     return thePrevious;
-  FeaturePtr aFeature = SketchPlugin_Sketch::getFeature(anAttr->object());
+  FeaturePtr aFeature = ModelAPI_Feature::feature(anAttr->object());
   if (!aFeature || aFeature->getKind() != SketchPlugin_Line::ID())
     return thePrevious;
 
index 4a971e8c7e3c27ab72870d3dfef5d49b6a863d55..e2cd9c53dd2d52ab8b5ee548dd945362999502ac 100644 (file)
@@ -45,13 +45,13 @@ boost::shared_ptr<GeomAPI_AISObject> SketchPlugin_ConstraintParallel::getAISObje
       !anAttr2 || !anAttr2->isObject())
     return thePrevious;
 
-  FeaturePtr aFeature = SketchPlugin_Sketch::getFeature(anAttr1->object());
+  FeaturePtr aFeature = ModelAPI_Feature::feature(anAttr1->object());
   if (!aFeature)
     return thePrevious;
   boost::shared_ptr<SketchPlugin_Line> aLine1Feature = 
     boost::dynamic_pointer_cast<SketchPlugin_Line>(aFeature);
 
-  aFeature = SketchPlugin_Sketch::getFeature(anAttr2->object());
+  aFeature = ModelAPI_Feature::feature(anAttr2->object());
   if (!aFeature)
     return thePrevious;
   boost::shared_ptr<SketchPlugin_Line> aLine2Feature = 
index 8985eb061bb3f6ef15164d7b61e0d4801b296b3c..4f6a0b77136a4e5ef3794a065b23e310233689ef 100644 (file)
@@ -45,13 +45,13 @@ boost::shared_ptr<GeomAPI_AISObject> SketchPlugin_ConstraintPerpendicular::getAI
       !anAttr2 || !anAttr2->isObject())
     return thePrevious;
 
-  FeaturePtr aFeature = SketchPlugin_Sketch::getFeature(anAttr1->object());
+  FeaturePtr aFeature = ModelAPI_Feature::feature(anAttr1->object());
   if (!aFeature)
     return thePrevious;
   boost::shared_ptr<SketchPlugin_Line> aLine1Feature = 
     boost::dynamic_pointer_cast<SketchPlugin_Line>(aFeature);
 
-  aFeature = SketchPlugin_Sketch::getFeature(anAttr2->object());
+  aFeature = ModelAPI_Feature::feature(anAttr2->object());
   if (!aFeature)
     return thePrevious;
   boost::shared_ptr<SketchPlugin_Line> aLine2Feature = 
index 11071843f283cd2801d576cdc3c61d45f3a31ea6..b771035423ffbe373fbf492317700b4f997323e0 100644 (file)
@@ -37,7 +37,7 @@ void SketchPlugin_ConstraintRadius::execute()
 
     boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
       boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(data()->attribute(SketchPlugin_Constraint::ENTITY_A()));
-    FeaturePtr aFeature = SketchPlugin_Sketch::getFeature(aRef->object());
+    FeaturePtr aFeature = ModelAPI_Feature::feature(aRef->object());
     if (aFeature) {
       double aRadius = 0;
       boost::shared_ptr<ModelAPI_Data> aData = aFeature->data();
@@ -73,7 +73,7 @@ boost::shared_ptr<GeomAPI_AISObject> SketchPlugin_ConstraintRadius::getAISObject
     boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_A()));
   if (!anAttr)
     return thePrevious;
-  FeaturePtr aFeature = SketchPlugin_Sketch::getFeature(anAttr->object());
+  FeaturePtr aFeature = ModelAPI_Feature::feature(anAttr->object());
   std::string aKind = aFeature ? aFeature->getKind() : "";
   if (aKind != SketchPlugin_Circle::ID() && aKind != SketchPlugin_Arc::ID())
     return thePrevious;
@@ -130,7 +130,7 @@ void SketchPlugin_ConstraintRadius::move(double theDeltaX, double theDeltaY)
 
   boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
     boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(data()->attribute(SketchPlugin_Constraint::ENTITY_A()));
-  FeaturePtr aFeature = SketchPlugin_Sketch::getFeature(aRef->object());
+  FeaturePtr aFeature = ModelAPI_Feature::feature(aRef->object());
   if (!aFeature)
     return;
   std::string aCenterAttrName;
index 8c9de8767b5200a08ee51334b94b0baad7e5fd05..2a05d45641cd3c9e5dca8516904eec7bd6e224cd 100644 (file)
@@ -24,6 +24,7 @@ SketchPlugin_Plugin::SketchPlugin_Plugin()
 {
   PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
   ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
+  aFactory->registerValidator("SketchPlugin_DistanceAttrValidator", new SketchPlugin_DistanceAttrValidator);
 
   // register this plugin
   ModelAPI_PluginManager::get()->registerPlugin(this);
index b2541dd8ed20685860f71cf841ec4406d14df8ad..b3cacc6ae777b297067e9935282790f6116cff84 100644 (file)
@@ -167,16 +167,3 @@ boost::shared_ptr<GeomAPI_AISObject> SketchPlugin_Sketch::
   }
   return boost::shared_ptr<GeomAPI_AISObject>();
 }
-
-FeaturePtr SketchPlugin_Sketch::getFeature(ObjectPtr theObject)
-{
-  FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(theObject);
-  if (!aFeature) {
-    ResultPtr aResult = boost::dynamic_pointer_cast<ModelAPI_Result>(theObject);
-    if (aResult) {
-      DocumentPtr aDoc = aResult->document();
-      return aDoc->feature(aResult);
-    }
-  }
-  return aFeature;
-}
\ No newline at end of file
index 374f8a9e1d9cf1ae62458093272301f17b6cdb1f..8a1d22db4701ad7fa263979b921ebc1058e9b67b 100644 (file)
@@ -96,8 +96,6 @@ public:
   virtual boost::shared_ptr<GeomAPI_AISObject> getAISObject(
                             boost::shared_ptr<GeomAPI_AISObject> thePrevious);
 
-  static FeaturePtr getFeature(ObjectPtr theObject);
-
 protected:
   /// Creates a plane and append it to the list
   /// \param theX the X normal value
index 161a1442c37dcf3930a90631b421c55549d2347e..862a30344b9dc328c1d9a5c7084ad282dfde7098 100644 (file)
@@ -3,55 +3,33 @@
 // Author:      Vitaly SMETANNIKOV
 
 #include "SketchPlugin_Validators.h"
-#include "SketchPlugin_Constraint.h"
-#include "SketchPlugin_Sketch.h"
-#include "SketchPlugin_Point.h"
-#include "SketchPlugin_Line.h"
-#include "SketchPlugin_Circle.h"
-#include "SketchPlugin_Arc.h"
+#include "SketchPlugin_ConstraintDistance.h"
 #include <ModelAPI_Data.h>
+#include <ModelAPI_Validator.h>
+#include <ModelAPI_ResultValidator.h>
+#include <GeomDataAPI_Point2D.h>
 
 
-bool isValidType(const std::string& theType)
+bool SketchPlugin_DistanceAttrValidator::isValid(const FeaturePtr& theFeature, 
+                                                 const std::list<std::string>& theArguments,
+                                                 const ObjectPtr& theObject) const
 {
-  return (theType == SketchPlugin_Point::ID()) || 
-         (theType == SketchPlugin_Circle::ID()) ||
-         (theType == SketchPlugin_Arc::ID());
+  std::string aParamA = theArguments.front();
+  PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
+  ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
+
+  // If the object is not a line then it is accepted
+  const ModelAPI_ResultValidator* aLineValidator = dynamic_cast<const ModelAPI_ResultValidator*>(
+                                              aFactory->validator("Model_ResultLineValidator"));
+  if (!aLineValidator->isValid(theObject))
+    return true;
+
+  // If it is a line then we have to check that first attribute id not a line
+  boost::shared_ptr<GeomDataAPI_Point2D> aPoint = getFeaturePoint(theFeature->data(), aParamA);
+  if (aPoint)
+    return true;
+  return false;
 }
 
-bool SketchPlugin_DistanceFeatureValidator::isValid(const FeaturePtr theFeature) const
-{
-  if (!theFeature)
-    return false;
-  if (!theFeature->data() || !theFeature->data()->isValid())
-    return false;
-  boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
-
-  boost::shared_ptr<ModelAPI_AttributeRefAttr> aRefA =
-          boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
-          aData->attribute(SketchPlugin_Constraint::ENTITY_A()));
-
-  boost::shared_ptr<ModelAPI_AttributeRefAttr> aRefB =
-          boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
-          aData->attribute(SketchPlugin_Constraint::ENTITY_B()));
-
-  if (!aRefA || !aRefB)
-    return false;
-
-  return true;
-/*  FeaturePtr aFetureA = SketchPlugin_Sketch::getFeature(aRefA->object());
-  FeaturePtr aFetureB = SketchPlugin_Sketch::getFeature(aRefB->object());
-  if (!aFetureA || !aFetureB)
-    return false;
-
-  std::string aTypeA = aFetureA->getKind();
-  std::string aTypeB = aFetureB->getKind();
-
-  if (aTypeA == SketchPlugin_Line::ID()) {
-    return isValidType(aTypeB);
-  } else if (aTypeB == SketchPlugin_Line::ID()) {
-    return isValidType(aTypeA);
-  } else
-    return isValidType(aTypeA) && isValidType(aTypeB);
-  return false;*/
-}
+
+
index 2941485cfb6aab361c74e2d07cf265379e525d1e..74357d1eb24e5a10e4564f83b563727d61b3039a 100644 (file)
@@ -6,14 +6,17 @@
 #define SketchPlugin_Validators_H
 
 #include "SketchPlugin.h"
-#include <ModuleBase_FeatureValidator.h>
+//#include <ModuleBase_FeatureValidator.h>
+#include <ModelAPI_AttributeValidator.h>
 
 
-//! A class to validate a selection for Perpendicular constraint operation
-class SketchPlugin_DistanceFeatureValidator: public ModuleBase_FeatureValidator
+class SketchPlugin_DistanceAttrValidator: public ModelAPI_AttributeValidator
 {
 public:
-  SKETCHPLUGIN_EXPORT virtual bool isValid(const FeaturePtr theFeature) const;
+  virtual bool isValid(const FeaturePtr& theFeature, 
+                       const std::list<std::string>& theArguments,
+                       const ObjectPtr& theObject) const;
+
 };
 
 #endif
\ No newline at end of file
index ed01bb4ca12cc34889bdba4c878842ae1ef10e61..804f1bb32609a9d858b818f13d125e28a5a2cf43 100644 (file)
       <feature id="SketchConstraintDistance" title="Distance" tooltip="Create constraint for the distance from a point to an object">
         <label title="Select point and another feature (point or point on line) between which to calculate distance" tooltip="Select point and another feature (point or point on line) between which to calculate distance"/>
         <feature_or_attribute_selector id="ConstraintEntityA" label="First object" tooltip="Select an point in the viewer">
-          <validator id="ModuleBase_ResultPointValidator"/>
-          <validator id="ModuleBase_ResultLineValidator"/>
+          <validator id="Model_ResultPointValidator"/>
+          <validator id="Model_ResultLineValidator"/>
         </feature_or_attribute_selector>
         <feature_or_attribute_selector id="ConstraintEntityB" label="Last object" tooltip="Select an point in the viewer">
-          <validator id="ModuleBase_ResultPointValidator"/>
-          <validator id="ModuleBase_ResultLineValidator"/>
+          <validator id="Model_ResultPointValidator"/>
+          <validator id="Model_ResultLineValidator"/>
+          <validator id="SketchPlugin_DistanceAttrValidator" parameters="ConstraintEntityA"/>
         </feature_or_attribute_selector>
         <point_selector id="ConstraintFlyoutValuePnt" internal="1"/>
         <doublevalue_editor label="Value" tooltip="Constraint value" id="ConstraintValue"/>
@@ -44,7 +45,7 @@
       <feature id="SketchConstraintLength" title="Length" tooltip="Create constraint for the given length of a line segment">
         <label title="Select a line on which to calculate lenght" tooltip="Select a line on which to calculate lenght"/>
         <feature_selector id="ConstraintEntityA" label="Line" tooltip="Select an line in the viewer">
-          <validator id="ModuleBase_ResultLineValidator"/>
+          <validator id="Model_ResultLineValidator"/>
         </feature_selector>
         <point_selector id="ConstraintFlyoutValuePnt" internal="1"/>
         <doublevalue_editor label="Value" tooltip="Constraint value" id="ConstraintValue"/>
@@ -54,7 +55,7 @@
       <feature id="SketchConstraintRadius" title="Radius" tooltip="Create constraint for the given radius of a circle or an arc">
         <label title="Select a circle or an arc on which to calculate radius" tooltip="Select a circle or an arc on which to calculate radius"/>
         <feature_selector id="ConstraintEntityA" label="Circle or Arc" tooltip="Select a circle or an arc in the viewer">
-          <validator id="ModuleBase_ResultArcValidator"/>
+          <validator id="Model_ResultArcValidator"/>
         </feature_selector>
         <point_selector id="ConstraintFlyoutValuePnt" internal="1"/>
         <doublevalue_editor label="Value" tooltip="Constraint value" id="ConstraintValue"/>
       
       <feature id="SketchConstraintParallel" title="Parallel" tooltip="Create constraint defining two parallel lines">
         <feature_selector id="ConstraintEntityA" label="First line" tooltip="Select an line in the viewer">
-          <validator id="ModuleBase_ResultLineValidator"/>
+          <validator id="Model_ResultLineValidator"/>
         </feature_selector>
         <feature_selector id="ConstraintEntityB" label="Last line" tooltip="Select an line in the viewer">
-          <validator id="ModuleBase_ResultLineValidator"/>
+          <validator id="Model_ResultLineValidator"/>
         </feature_selector>
         <point_selector id="ConstraintFlyoutValuePnt" internal="1"/>
         <validator id="PartSet_ParallelValidator"/>
       
       <feature id="SketchConstraintPerpendicular" title="Perpendicular" tooltip="Create constraint defining two perpendicular lines">
         <feature_selector id="ConstraintEntityA" label="First line" tooltip="Select an line in the viewer">
-          <validator id="ModuleBase_ResultLineValidator"/>
+          <validator id="Model_ResultLineValidator"/>
         </feature_selector>
         <feature_selector id="ConstraintEntityB" label="Last line" tooltip="Select an line in the viewer">
-          <validator id="ModuleBase_ResultLineValidator"/>
+          <validator id="Model_ResultLineValidator"/>
         </feature_selector>
         <point_selector id="ConstraintFlyoutValuePnt" internal="1"/>
         <validator id="PartSet_PerpendicularValidator"/>
index bc349421974a2661d0e9e0dd8ed8959b63652773..62c735ce71e89d1e546a6d5802831bd602a071c3 100644 (file)
@@ -6,11 +6,11 @@
 #include "XGUI_Viewer.h"
 #include "XGUI_Workshop.h"
 #include "XGUI_ViewerProxy.h"
-#include "ModuleBase_Tools.h"
 
 #include <ModelAPI_Document.h>
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Object.h>
+#include <ModelAPI_Tools.h>
 
 #include <GeomAPI_Shape.h>
 #include <GeomAPI_IPresentable.h>
@@ -54,7 +54,7 @@ void XGUI_Displayer::display(ObjectPtr theObject, bool isUpdateViewer)
     } else {
       ResultPtr aResult = boost::dynamic_pointer_cast<ModelAPI_Result>(theObject);
       if (aResult) {
-        boost::shared_ptr<GeomAPI_Shape> aShapePtr = ModuleBase_Tools::shape(aResult);
+        boost::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
         if (aShapePtr) {
           anAIS = boost::shared_ptr<GeomAPI_AISObject>(new GeomAPI_AISObject());
           anAIS->createShape(aShapePtr);
@@ -144,7 +144,7 @@ void XGUI_Displayer::redisplay(ObjectPtr theObject, bool isUpdateViewer)
   } else {
     ResultPtr aResult = boost::dynamic_pointer_cast<ModelAPI_Result>(theObject);
     if (aResult) {
-      boost::shared_ptr<GeomAPI_Shape> aShapePtr = ModuleBase_Tools::shape(aResult);
+      boost::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
       if (aShapePtr) {
         Handle(AIS_Shape) aAISShape = Handle(AIS_Shape)::DownCast(aAISObj->impl<Handle(AIS_InteractiveObject)>());
         if (!aAISShape.IsNull()) {
index 99f8b066da82feb19b8ebb00cb198f87658d4ca4..5b26e4e6a8f62b7937613382b6bfcceb36a598b0 100644 (file)
@@ -144,7 +144,8 @@ QWidget* XGUI_PropertyPanel::contentWidget()
 void XGUI_PropertyPanel::updateContentWidget(FeaturePtr theFeature)
 {
   foreach(ModuleBase_ModelWidget* eachWidget, myWidgets) {
-    eachWidget->restoreValue(theFeature);
+    eachWidget->setFeature(theFeature);
+    eachWidget->restoreValue();
   }
   // the repaint is used here to immediatelly react in GUI to the values change.
   repaint();
index 58650d5c423257ffcacc27c774f50093a5b2eb63..adc15c34041928ca0a51df06e817624db601c9bf 100644 (file)
@@ -403,12 +403,15 @@ void XGUI_Workshop::onOperationStarted()
     ModuleBase_ModelWidget* aWidget;
     for (; anIt != aLast; anIt++) {
       aWidget = *anIt;
+      aWidget->setFeature(aOperation->feature());
       //QObject::connect(aWidget, SIGNAL(valuesChanged()),  aOperation, SLOT(storeCustomValue()));
       QObject::connect(aWidget, SIGNAL(valuesChanged()),
                        this, SLOT(onWidgetValuesChanged()));
       // Init default values
       if (!aOperation->isEditOperation() && aWidget->hasDefaultValue()) {
-        aWidget->storeValue(aOperation->feature());
+        //aWidget->storeValue(aOperation->feature());
+        
+        aWidget->storeValue();
       }
     }
 
@@ -940,7 +943,8 @@ void XGUI_Workshop::onWidgetValuesChanged()
   for (; anIt != aLast; anIt++) {
     ModuleBase_ModelWidget* aCustom = *anIt;
     if (aCustom && (/*!aCustom->isInitialized(aFeature) ||*/ aCustom == aSenderWidget)) {
-      aCustom->storeValue(aFeature);
+      //aCustom->storeValue(aFeature);
+      aCustom->storeValue();
     }
   }
 }
@@ -1043,10 +1047,6 @@ void XGUI_Workshop::registerValidators() const
 {
   PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
   ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
-
-  aFactory->registerValidator("ModuleBase_ResultPointValidator", new ModuleBase_ResultPointValidator);
-  aFactory->registerValidator("ModuleBase_ResultLineValidator", new ModuleBase_ResultLineValidator);
-  aFactory->registerValidator("ModuleBase_ResultArcValidator", new ModuleBase_ResultArcValidator);
 }