]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #115 The "computed" for all constraints
authorsbh <sergey.belash@opencascade.com>
Thu, 11 Sep 2014 12:17:50 +0000 (16:17 +0400)
committersbh <sergey.belash@opencascade.com>
Thu, 11 Sep 2014 12:17:50 +0000 (16:17 +0400)
src/ModelAPI/ModelAPI_Attribute.h
src/ModuleBase/ModuleBase_ModelWidget.cpp
src/ModuleBase/ModuleBase_ModelWidget.h
src/ModuleBase/ModuleBase_WidgetFeature.cpp
src/ModuleBase/ModuleBase_WidgetFeatureOrAttribute.cpp
src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp
src/SketchPlugin/SketchPlugin_ConstraintLength.cpp
src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp
src/SketchPlugin/plugin-Sketch.xml

index e868e0d31b3a73d461eb385989a301f33d82ae4d..a73044d4a1ebcd57319cc2cd3548bb3ef7e55f9f 100644 (file)
@@ -22,7 +22,6 @@ class ModelAPI_Attribute
  protected:
   // accessible from the attributes
   bool myIsInitialized;
-  bool myIsComputedDefault;
   bool myIsArgument;
  public:
 
@@ -58,19 +57,6 @@ class ModelAPI_Attribute
     myIsInitialized = true;
   }
 
-  /// Returns true if attribute's default value was computed
-  MODELAPI_EXPORT bool isComputedDefault()
-  {
-    return myIsComputedDefault;
-  }
-
-  /// Tells that attribute's default value was computed
-  MODELAPI_EXPORT void setComputedDefault()
-  {
-    myIsComputedDefault = true;
-    myIsInitialized = false;
-  }
-
   /// Set this attribute is argument for result (change of this attribute requires update of result).
   /// By default it is true.
   MODELAPI_EXPORT void setIsArgument(const bool theFlag)
@@ -89,7 +75,6 @@ class ModelAPI_Attribute
   ModelAPI_Attribute()
   {
     myIsInitialized = false;
-    myIsComputedDefault = false;
     myIsArgument = true;
   }
 
index 11d5f15fc8f4fba2d437622e1307ae110888dd25..12e0e034c54747ed71843b15c3a9591faa04f1bb 100644 (file)
@@ -28,12 +28,6 @@ bool ModuleBase_ModelWidget::isInitialized(ObjectPtr theObject) const
   return theObject->data()->attribute(attributeID())->isInitialized();
 }
 
-void ModuleBase_ModelWidget::setAttributeComputedState(ObjectPtr theObject) const
-{
-  if(myIsComputedDefault)
-    theObject->data()->attribute(attributeID())->setComputedDefault();
-}
-
 bool ModuleBase_ModelWidget::focusTo()
 {
   QList<QWidget*> aControls = getControls();
index 9e790a3361c3490c56f22638d599e6e4c80bf5c2..400a90249682c75fcab09ffdf82b420d2e363f8d 100644 (file)
@@ -52,8 +52,6 @@ Q_OBJECT
   /// \return the boolean result
   bool isInitialized(ObjectPtr theObject) const;
 
-  void setAttributeComputedState(ObjectPtr theObject) const;
-
   bool isComputedDefault()
   {
     return myIsComputedDefault;
@@ -95,8 +93,6 @@ Q_OBJECT
   void setFeature(const FeaturePtr& theFeature)
   {
     myFeature = theFeature;
-    if(theFeature)
-     setAttributeComputedState(theFeature);
   }
 
 signals:
index e7c510a8385a0cfaea7d3fa94b6e5eb16246289a..ec61e844359fb6e23b90305821edb52b0b755ce5 100644 (file)
@@ -137,10 +137,9 @@ bool ModuleBase_WidgetFeature::restoreValue()
   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;
+  ObjectPtr anObjPtr = aRef->object();
+  if (anObjPtr) {
+    myObject = anObjPtr;
     myEditor->setText(myObject ? myObject->data()->name().c_str() : "");
     return true;
   }
index 4481c2034654e25aea8f69e42204e45bfe288eb0..d9674c4d45d7e0856c33fed4b493c160f280f8f8 100644 (file)
@@ -30,8 +30,9 @@
 #include <QHBoxLayout>
 #include <QLabel>
 
-ModuleBase_WidgetFeatureOrAttribute::ModuleBase_WidgetFeatureOrAttribute(
-    QWidget* theParent, const Config_WidgetAPI* theData, const std::string& theParentId)
+ModuleBase_WidgetFeatureOrAttribute::ModuleBase_WidgetFeatureOrAttribute(QWidget* theParent, 
+                                                                         const Config_WidgetAPI* theData, 
+                                                                         const std::string& theParentId)
     : ModuleBase_WidgetFeature(theParent, theData, theParentId)
 {
 }
index 97a08e13403e3f60850dd654e88b9b832bfeb917..60c3e23b1f17bcadd58672db383d9db6b09536c4 100644 (file)
@@ -33,29 +33,37 @@ void SketchPlugin_ConstraintDistance::initAttributes()
 void SketchPlugin_ConstraintDistance::execute()
 {
   boost::shared_ptr<ModelAPI_Data> aData = data();
-  AttributeDoublePtr anAttr_Value = boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
+  AttributeDoublePtr anAttrValue = boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
       aData->attribute(SketchPlugin_Constraint::VALUE()));
 
-  boost::shared_ptr<GeomDataAPI_Point2D> aPoint_A = getFeaturePoint(
-      aData, SketchPlugin_Constraint::ENTITY_A());
-  boost::shared_ptr<GeomDataAPI_Point2D> aPoint_B = getFeaturePoint(
-      aData, SketchPlugin_Constraint::ENTITY_B());
-
-  if (aPoint_A && aPoint_B) {  // both points
-    anAttr_Value->setValue(aPoint_A->pnt()->distance(aPoint_B->pnt()));
+  if(anAttrValue->isInitialized())
+    return;
+  boost::shared_ptr<GeomDataAPI_Point2D> aPointA =
+      getFeaturePoint(aData, SketchPlugin_Constraint::ENTITY_A());
+  boost::shared_ptr<GeomDataAPI_Point2D> aPointB =
+      getFeaturePoint(aData, SketchPlugin_Constraint::ENTITY_B());
+
+  double aDistance = -1.;
+  if (aPointA && aPointB) {  // both points
+    aDistance = aPointA->pnt()->distance(aPointB->pnt());
   } else {
-    if (!aPoint_A && aPoint_B) {  //Line and point
-      boost::shared_ptr<SketchPlugin_Line> aLine = getFeatureLine(
-          aData, SketchPlugin_Constraint::ENTITY_A());
-      if (aLine)
-        anAttr_Value->setValue(aLine->distanceToPoint(aPoint_B->pnt()));
-    } else if (aPoint_A && !aPoint_B) {  // Point and line
-      boost::shared_ptr<SketchPlugin_Line> aLine = getFeatureLine(
-          aData, SketchPlugin_Constraint::ENTITY_B());
-      if (aLine)
-        anAttr_Value->setValue(aLine->distanceToPoint(aPoint_A->pnt()));
+    if (!aPointA && aPointB) {  //Line and point
+      boost::shared_ptr<SketchPlugin_Line> aLine =
+          getFeatureLine(aData, SketchPlugin_Constraint::ENTITY_A());
+      if (aLine) {
+        aDistance = aLine->distanceToPoint(aPointB->pnt());
+      }
+    } else if (aPointA && !aPointB) {  // Point and line
+      boost::shared_ptr<SketchPlugin_Line> aLine =
+          getFeatureLine(aData, SketchPlugin_Constraint::ENTITY_B());
+      if (aLine) {
+        aDistance = aLine->distanceToPoint(aPointA->pnt());
+      }
     }
   }
+  if(aDistance >= 0) {
+    anAttrValue->setValue(aDistance);
+  }
 }
 
 //*************************************************************************************
index e7ed5411ccb608c54e03e606d0b20b994ed4c0dd..d0ca9f88b565348aefca50c352ae49866b790328 100644 (file)
@@ -45,7 +45,9 @@ void SketchPlugin_ConstraintLength::execute()
 
     boost::shared_ptr<ModelAPI_AttributeDouble> aValueAttr = boost::dynamic_pointer_cast<
         ModelAPI_AttributeDouble>(data()->attribute(SketchPlugin_Constraint::VALUE()));
-    aValueAttr->setValue(aLenght);
+    if(!aValueAttr->isInitialized()) {
+      aValueAttr->setValue(aLenght);
+    }
   }
 }
 
index 133bc91bb74e8639694c2193eb7e372e1b58518d..36ec6c384b0f9d7e9231dddf90d408ac268575a9 100644 (file)
@@ -55,7 +55,9 @@ void SketchPlugin_ConstraintRadius::execute()
     }
     boost::shared_ptr<ModelAPI_AttributeDouble> aValueAttr = boost::dynamic_pointer_cast<
         ModelAPI_AttributeDouble>(data()->attribute(SketchPlugin_Constraint::VALUE()));
-    aValueAttr->setValue(aRadius);
+    if(!aValueAttr->isInitialized()) {
+      aValueAttr->setValue(aRadius);
+    }
   }
 }
 
index 4a0088d51e27bcba6eb266a9e40c8a54e35348a2..c40bcaffb5ec0e1aff04dc9f539af562e9f4d021 100644 (file)
@@ -40,7 +40,7 @@
           <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"/>
+        <doublevalue_editor label="Value" tooltip="Constraint value" id="ConstraintValue" default="computed"/>
         <validator id="PartSet_DistanceValidator"/>
       </feature>
       
@@ -50,7 +50,7 @@
           <validator id="SketchPlugin_ResultLineValidator"/>
         </feature_selector>
         <point_selector id="ConstraintFlyoutValuePnt" internal="1"/>
-        <doublevalue_editor label="Value" tooltip="Constraint value" id="ConstraintValue"/>
+        <doublevalue_editor label="Value" tooltip="Constraint value" id="ConstraintValue" default="computed"/>
         <validator id="PartSet_LengthValidator"/> 
       </feature>