]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Validator for tangent arc creation
authorazv <azv@opencascade.com>
Thu, 4 Feb 2016 07:44:50 +0000 (10:44 +0300)
committerdbv <dbv@opencascade.com>
Tue, 16 Feb 2016 14:04:36 +0000 (17:04 +0300)
src/SketchPlugin/SketchPlugin_Plugin.cpp
src/SketchPlugin/SketchPlugin_Validators.cpp
src/SketchPlugin/SketchPlugin_Validators.h
src/SketchPlugin/plugin-Sketch.xml

index a07675a5399bd9ad736d020b0f81c513ad5874ea..6cd164a88613c4a260c1648ccf6998ef06a89bda 100644 (file)
@@ -76,6 +76,8 @@ SketchPlugin_Plugin::SketchPlugin_Plugin()
                               new SketchPlugin_FilletVertexValidator);
   aFactory->registerValidator("SketchPlugin_MiddlePointAttr",
                               new SketchPlugin_MiddlePointAttrValidator);
+  aFactory->registerValidator("SketchPlugin_ArcTangentPoint",
+                              new SketchPlugin_ArcTangentPointValidator);
 
   // register this plugin
   ModelAPI_Session::get()->registerPlugin(this);
@@ -192,6 +194,7 @@ std::shared_ptr<ModelAPI_FeatureStateMessage> SketchPlugin_Plugin
       aMsg->setState(SketchPlugin_Circle::ID(), aHasSketchPlane);
       aMsg->setState(SketchPlugin_Arc::ID(), aHasSketchPlane);
       aMsg->setState(SketchPlugin_ConstraintCoincidence::ID(), aHasSketchPlane);
+      aMsg->setState(SketchPlugin_ConstraintCollinear::ID(), aHasSketchPlane);
       aMsg->setState(SketchPlugin_ConstraintDistance::ID(), aHasSketchPlane);
       aMsg->setState(SketchPlugin_ConstraintLength::ID(), aHasSketchPlane);
       aMsg->setState(SketchPlugin_ConstraintParallel::ID(), aHasSketchPlane);
@@ -202,6 +205,7 @@ std::shared_ptr<ModelAPI_FeatureStateMessage> SketchPlugin_Plugin
       aMsg->setState(SketchPlugin_ConstraintVertical::ID(), aHasSketchPlane);
       aMsg->setState(SketchPlugin_ConstraintEqual::ID(), aHasSketchPlane);
       aMsg->setState(SketchPlugin_ConstraintTangent::ID(), aHasSketchPlane);
+      aMsg->setState(SketchPlugin_ConstraintMiddle::ID(), aHasSketchPlane);
       aMsg->setState(SketchPlugin_ConstraintMirror::ID(), aHasSketchPlane);
       aMsg->setState(SketchPlugin_ConstraintFillet::ID(), aHasSketchPlane);
       aMsg->setState(SketchPlugin_ConstraintAngle::ID(), aHasSketchPlane);
index 9ac7fec38ced2bf36cc5332a4b84f87460046722..a29070b1f7e2f8b48834ebb1ef3133e7fe01cc29 100755 (executable)
@@ -650,3 +650,44 @@ bool SketchPlugin_MiddlePointAttrValidator::isValid(const AttributePtr& theAttri
   }
   return true;
 }
+
+bool SketchPlugin_ArcTangentPointValidator::isValid(const AttributePtr& theAttribute,
+                                                    const std::list<std::string>& /*theArguments*/,
+                                                    std::string& theError) const
+{
+  if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
+    theError = "The attribute with the " + theAttribute->attributeType() + " type is not processed";
+    return false;
+  }
+  AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
+  AttributePtr anAttr = aRefAttr->attr();
+  if (!anAttr) {
+    theError = "The attribute " + theAttribute->id() + " should be a point";
+    return false;
+  }
+
+  FeaturePtr anAttrFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anAttr->owner());
+  const std::string& aFeatureType = anAttrFeature->getKind();
+  if (aFeatureType == SketchPlugin_Arc::ID()) {
+    // selected point should not be a center of arc
+    const std::string& aPntId = anAttr->id();
+    if (aPntId != SketchPlugin_Arc::START_ID() && aPntId != SketchPlugin_Arc::END_ID()) {
+      theError = "The attribute " + aPntId + " is not supported";
+      return false;
+    }
+  }
+  else if (aFeatureType == SketchPlugin_Line::ID()) {
+    // selected point should be bound point of line
+    const std::string& aPntId = anAttr->id();
+    if (aPntId != SketchPlugin_Line::START_ID() && aPntId != SketchPlugin_Line::END_ID()) {
+      theError = "The attribute " + aPntId + " is not supported";
+      return false;
+    }
+  }
+  else {
+    theError = "Unable to build tangent arc on " + anAttrFeature->getKind();
+    return false;
+  }
+
+  return true;
+}
index 86f8ee295bc351e3fe013d581666fbbb7716bd6d..ef5e77aba44997a768d4d1b979f1243e5445ac2d 100644 (file)
@@ -199,4 +199,23 @@ class SketchPlugin_MiddlePointAttrValidator : public ModelAPI_AttributeValidator
                        std::string& theError) const;
 };
 
+
+/**\class SketchPlugin_ArcTangentPointValidator
+ * \ingroup Validators
+ * \brief Validator for the point where the tangent arc is building.
+ *
+ * Checks that the point is a start or end point just on line or arc.
+ */
+class SketchPlugin_ArcTangentPointValidator : public ModelAPI_AttributeValidator
+{
+ public:
+  //! returns true if attribute is valid
+  //! \param theAttribute the checked attribute
+  //! \param theArguments arguments of the attribute
+  //! \param theError error message
+  virtual bool isValid(const AttributePtr& theAttribute,
+                       const std::list<std::string>& theArguments,
+                       std::string& theError) const;
+};
+
 #endif
index 68e7e32f0a9b8753f46e8c1cb8dc29600cf2c235..deaee27b974d03400e8c5cb98f568660b595f563 100644 (file)
@@ -77,7 +77,9 @@
             <validator id="GeomValidators_Different" parameters="ArcStartPoint,ArcEndPoint,ArcPassedPoint"/>
           </box>
           <box id="Tangent" title="Tangent with edge" icon=":icons/arc_tang_32x32.png">
-            <sketch_shape_selector id="ArcTangentPoint" label="Start point" tooltip="Select point on line" shape_types="vertex" />
+            <sketch_shape_selector id="ArcTangentPoint" label="Start point" tooltip="Select point on line" shape_types="vertex">
+              <validator id="SketchPlugin_ArcTangentPoint" parameters="" />
+            </sketch_shape_selector>
             <sketch-2dpoint_selector id="ArcEndPoint" accept_expressions="0" title="End point" tooltip="End point"/>
             <doublevalue id="ArcRadius" accept_expressions="0" label="Radius:" default="computed" icon=":icons/radius.png" tooltip="Set radius" obligatory="1">
               <validator id="GeomValidators_Positive"/>