]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Provide distance between points of lines
authorvsv <vitaly.smetannikov@opencascade.com>
Wed, 30 Jul 2014 07:31:38 +0000 (11:31 +0400)
committervsv <vitaly.smetannikov@opencascade.com>
Wed, 30 Jul 2014 07:31:38 +0000 (11:31 +0400)
src/ModuleBase/ModuleBase_ResultValidators.cpp
src/ModuleBase/ModuleBase_ResultValidators.h
src/ModuleBase/ModuleBase_WidgetFeatureOrAttribute.cpp
src/ModuleBase/ModuleBase_WidgetFeatureOrAttribute.h
src/SketchPlugin/plugin-Sketch.xml
src/XGUI/XGUI_Workshop.cpp

index 548fc549cf307a3557b4cf2c4585c4c1c07c6d60..67a9ca5a992a8784ac82e673008449f34a388dab 100644 (file)
@@ -29,7 +29,7 @@ TopoDS_Shape shape(ResultPtr theResult)
 }
 
 
-bool ModuleBase_ResulPointValidator::isValid(const ObjectPtr theObject) const
+bool ModuleBase_ResultPointValidator::isValid(const ObjectPtr theObject) const
 {
   ResultPtr aResult = result(theObject);
   if (!aResult)
@@ -42,7 +42,7 @@ bool ModuleBase_ResulPointValidator::isValid(const ObjectPtr theObject) const
 }
 
 
-bool ModuleBase_ResulLineValidator::isValid(const ObjectPtr theObject) const
+bool ModuleBase_ResultLineValidator::isValid(const ObjectPtr theObject) const
 {
   ResultPtr aResult = result(theObject);
   if (!aResult)
@@ -62,7 +62,7 @@ bool ModuleBase_ResulLineValidator::isValid(const ObjectPtr theObject) const
 }
 
 
-bool ModuleBase_ResulArcValidator::isValid(const ObjectPtr theObject) const
+bool ModuleBase_ResultArcValidator::isValid(const ObjectPtr theObject) const
 {
   ResultPtr aResult = result(theObject);
   if (!aResult)
index 50cc2e7b1de8acecad5ba2f20b7ba0b4295eadc6..1b55460e0e7e6925484dfe70834754ceca449b39 100644 (file)
@@ -15,19 +15,19 @@ public:
   virtual bool isValid(const ObjectPtr theObject) const = 0;
 };
 
-class ModuleBase_ResulPointValidator: public ModuleBase_ResultValidator
+class ModuleBase_ResultPointValidator: public ModuleBase_ResultValidator
 {
 public:
   MODULEBASE_EXPORT virtual bool isValid(const ObjectPtr theObject) const;
 };
 
-class ModuleBase_ResulLineValidator: public ModuleBase_ResultValidator
+class ModuleBase_ResultLineValidator: public ModuleBase_ResultValidator
 {
 public:
   MODULEBASE_EXPORT virtual bool isValid(const ObjectPtr theObject) const;
 };
 
-class ModuleBase_ResulArcValidator: public ModuleBase_ResultValidator
+class ModuleBase_ResultArcValidator: public ModuleBase_ResultValidator
 {
 public:
   MODULEBASE_EXPORT virtual bool isValid(const ObjectPtr theObject) const;
index 4b456e859a45c5d0541b785e129c2636ce0a6096..10f8ba4f3112a67dbe0da36da82343d7eacfe9fe 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <ModuleBase_WidgetValueFeature.h>
 #include <ModuleBase_WidgetValue.h>
+#include <ModuleBase_Tools.h>
 
 #include <Config_Keywords.h>
 #include <Config_WidgetAPI.h>
@@ -48,33 +49,39 @@ bool ModuleBase_WidgetFeatureOrAttribute::setValue(ModuleBase_WidgetValue* theVa
                          dynamic_cast<ModuleBase_WidgetValueFeature*>(theValue);
     if (aFeatureValue) {
       boost::shared_ptr<GeomAPI_Pnt2d> aValuePoint = aFeatureValue->point();
-      ObjectPtr aValueFeature = aFeatureValue->object();
-      if (aValueFeature) {
-        isDone = setObject(aValueFeature);
+      ObjectPtr aObject = aFeatureValue->object();
+      if (aObject) {
+        isDone = setObject(aObject);
       }
       if (!isDone && aValuePoint) {
-        // find the given point in the feature attributes
-        std::list<boost::shared_ptr<ModelAPI_Attribute> > anAttiributes =
-                                      aValueFeature->data()->attributes(GeomDataAPI_Point2D::type());
-        std::list<boost::shared_ptr<ModelAPI_Attribute> >::const_iterator anIt = anAttiributes.begin(),
-                                                                          aLast = anAttiributes.end();
-        boost::shared_ptr<GeomDataAPI_Point2D> aFPoint;
-        for (;anIt!=aLast && !aFPoint; anIt++) {
-          boost::shared_ptr<GeomDataAPI_Point2D> aCurPoint =
-                                              boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(*anIt);
-          if (aCurPoint && aCurPoint->pnt()->distance(aValuePoint) < Precision::Confusion())
-            aFPoint = aCurPoint;
+        FeaturePtr aFeature = ModuleBase_Tools::feature(aObject);
+        if (aFeature) {
+          // find the given point in the feature attributes
+          std::list<boost::shared_ptr<ModelAPI_Attribute> > anAttiributes =
+                                        aFeature->data()->attributes(GeomDataAPI_Point2D::type());
+          std::list<boost::shared_ptr<ModelAPI_Attribute> >::const_iterator anIt = anAttiributes.begin(),
+                                                                            aLast = anAttiributes.end();
+          boost::shared_ptr<GeomDataAPI_Point2D> aFPoint;
+          for (;anIt!=aLast && !aFPoint; anIt++) {
+            boost::shared_ptr<GeomDataAPI_Point2D> aCurPoint =
+                                                boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(*anIt);
+            if (aCurPoint && aCurPoint->pnt()->distance(aValuePoint) < Precision::Confusion())
+              aFPoint = aCurPoint;
+          }
+          if (aFPoint)
+            isDone = setAttribute(aFPoint);
         }
-        if (aFPoint)
-          isDone = setAttribute(aFPoint);
       }
     }
   }
   return isDone;
 }
 
-bool ModuleBase_WidgetFeatureOrAttribute::storeValue(FeaturePtr theFeature) const
+bool ModuleBase_WidgetFeatureOrAttribute::storeValue(ObjectPtr theFeature) const
 {
+  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_AttributeRefAttr> aRef =
           boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(attributeID()));
@@ -85,19 +92,19 @@ bool ModuleBase_WidgetFeatureOrAttribute::storeValue(FeaturePtr theFeature) cons
   else if (myAttribute)
     aRef->setAttr(myAttribute);
 
-  theFeature->execute();
+  aFeature->execute();
   updateObject(theFeature);
 
   return true;
 }
 
-bool ModuleBase_WidgetFeatureOrAttribute::restoreValue(FeaturePtr theFeature)
+bool ModuleBase_WidgetFeatureOrAttribute::restoreValue(ObjectPtr theFeature)
 {
   boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
   boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
           boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(attributeID()));
 
-  FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(aRef->object());
+  FeaturePtr aFeature = ModuleBase_Tools::feature(aRef->object());
   if (aFeature) {
     setObject(aFeature);
     myAttribute = aRef->attr();
@@ -116,7 +123,7 @@ bool ModuleBase_WidgetFeatureOrAttribute::restoreValue(FeaturePtr theFeature)
 
 bool ModuleBase_WidgetFeatureOrAttribute::setAttribute(const boost::shared_ptr<ModelAPI_Attribute>& theAttribute)
 {
-  if (!theAttribute || !featureKinds().contains(theAttribute->attributeType().c_str()))
+  if (!theAttribute)// || !featureKinds().contains(theAttribute->attributeType().c_str()))
     return false;
 
   myAttribute = theAttribute;
index dc9bad6d8b4e249c5703795411a93fca11416d30..54e2e08eb62a210e5e8e34660119acebe5b86c4d 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(FeaturePtr theFeature) const;
+  virtual bool storeValue(ObjectPtr theFeature) const;
 
-  virtual bool restoreValue(FeaturePtr theFeature);
+  virtual bool restoreValue(ObjectPtr theFeature);
 
 protected:
   /// Set the attribute
index e6d71aa232f7b64251fbce45bc64916a45764b58..ec1425964287f379225d733d4f3bf5ae5582431a 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 point" tooltip="Select an point in the viewer">
-          <validator id="ModuleBase_ResulPointValidator"/>
+          <validator id="ModuleBase_ResultPointValidator"/>
         </feature_or_attribute_selector>
         <feature_or_attribute_selector id="ConstraintEntityB" label="Last point" tooltip="Select an point in the viewer">
-          <validator id="ModuleBase_ResulPointValidator"/>
+          <validator id="ModuleBase_ResultPointValidator"/>
         </feature_or_attribute_selector>
         <point_selector id="ConstraintFlyoutValuePnt" internal="1"/>
         <doublevalue_editor label="Value" tooltip="Constraint value" id="ConstraintValue"/>
@@ -42,7 +42,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_ResulLineValidator"/>
+          <validator id="ModuleBase_ResultLineValidator"/>
         </feature_selector>
         <point_selector id="ConstraintFlyoutValuePnt" internal="1"/>
         <doublevalue_editor label="Value" tooltip="Constraint value" id="ConstraintValue"/>
@@ -52,7 +52,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_ResulArcValidator"/>
+          <validator id="ModuleBase_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_ResulLineValidator"/>
+          <validator id="ModuleBase_ResultLineValidator"/>
         </feature_selector>
         <feature_selector id="ConstraintEntityB" label="Last line" tooltip="Select an line in the viewer">
-          <validator id="ModuleBase_ResulLineValidator"/>
+          <validator id="ModuleBase_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_ResulLineValidator"/>
+          <validator id="ModuleBase_ResultLineValidator"/>
         </feature_selector>
         <feature_selector id="ConstraintEntityB" label="Last line" tooltip="Select an line in the viewer">
-          <validator id="ModuleBase_ResulLineValidator"/>
+          <validator id="ModuleBase_ResultLineValidator"/>
         </feature_selector>
         <point_selector id="ConstraintFlyoutValuePnt" internal="1"/>
         <validator id="PartSet_PerpendicularValidator"/>
index fe055eff44b0b246d1c2bc802299aa48d083eb60..a8d23dd5212af78cc510beffafac2f6a03ed8269 100644 (file)
@@ -1040,9 +1040,9 @@ void XGUI_Workshop::registerValidators() const
   PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
   ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
 
-  aFactory->registerValidator("ModuleBase_ResulPointValidator", new ModuleBase_ResulPointValidator);
-  aFactory->registerValidator("ModuleBase_ResulLineValidator", new ModuleBase_ResulLineValidator);
-  aFactory->registerValidator("ModuleBase_ResulArcValidator", new ModuleBase_ResulArcValidator);
+  aFactory->registerValidator("ModuleBase_ResultPointValidator", new ModuleBase_ResultPointValidator);
+  aFactory->registerValidator("ModuleBase_ResultLineValidator", new ModuleBase_ResultLineValidator);
+  aFactory->registerValidator("ModuleBase_ResultArcValidator", new ModuleBase_ResultArcValidator);
 }