]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #2024: Redesign of circle and arc of circle
authordbv <dbv@opencascade.com>
Mon, 27 Mar 2017 10:08:47 +0000 (13:08 +0300)
committerdbv <dbv@opencascade.com>
Mon, 27 Mar 2017 13:33:39 +0000 (16:33 +0300)
Updated validators for arc.

src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp
src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.h
src/SketchPlugin/SketchPlugin_MacroArc.cpp
src/SketchPlugin/SketchPlugin_MacroArc.h
src/SketchPlugin/SketchPlugin_Plugin.cpp
src/SketchPlugin/SketchPlugin_Validators.cpp
src/SketchPlugin/SketchPlugin_Validators.h
src/SketchPlugin/plugin-Sketch.xml

index 1df2c7f8745f37b64881a809f7885f922452a77e..cf3ab9623ab8d0a94497b6c1c3cd7b9f963551b2 100644 (file)
@@ -648,6 +648,27 @@ bool GeomAlgoAPI_ShapeTools::isSubShapeInsideShape(
   return true;
 }
 
+//==================================================================================================
+bool GeomAlgoAPI_ShapeTools::isShapesIntersects(
+  const std::shared_ptr<GeomAPI_Shape> theShape1,
+  const std::shared_ptr<GeomAPI_Shape> theShape2)
+{
+  if(!theShape1.get() || !theShape2.get()) {
+    return false;
+  }
+
+  const TopoDS_Shape& aShape1 = theShape1->impl<TopoDS_Shape>();
+  const TopoDS_Shape& aShape2 = theShape2->impl<TopoDS_Shape>();
+
+  BRepExtrema_DistShapeShape aDist(aShape1, aShape2);
+  aDist.Perform();
+  if(aDist.IsDone() && aDist.Value() < Precision::Confusion()) {
+    return true;
+  }
+
+  return false;
+}
+
 //==================================================================================================
 bool GeomAlgoAPI_ShapeTools::isShapeValid(const std::shared_ptr<GeomAPI_Shape> theShape)
 {
index d3b712585176a24a8e7316e42611d48153ebf8ba..e6df0520b50345f4cf85c1137641a4ec966f9044 100644 (file)
@@ -108,6 +108,14 @@ public:
     const std::shared_ptr<GeomAPI_Shape> theSubShape,
     const std::shared_ptr<GeomAPI_Shape> theBaseShape);
 
+  /// \brief Checks that shapes intersects.
+  /// \param[in] theShape1 first shape.
+  /// \param[in] theShape2 second shape.
+  /// \return true if shapes intersects.
+  GEOMALGOAPI_EXPORT static bool GeomAlgoAPI_ShapeTools::isShapesIntersects(
+    const std::shared_ptr<GeomAPI_Shape> theShape1,
+    const std::shared_ptr<GeomAPI_Shape> theShape2);
+
   /// \return true if theShape is valid.
   GEOMALGOAPI_EXPORT static bool isShapeValid(const std::shared_ptr<GeomAPI_Shape> theShape);
 
index 2ebb18dd4c3eea38e5fe8d3836d676f998ed2e27..de876dc966b433630f81fa2bd1f576587de39421 100644 (file)
@@ -148,28 +148,44 @@ void SketchPlugin_MacroArc::attributeChanged(const std::string& theID)
   data()->blockSendAttributeUpdated(aWasBlocked, false);
 }
 
-AISObjectPtr SketchPlugin_MacroArc::getAISObject(AISObjectPtr thePrevious)
+GeomShapePtr SketchPlugin_MacroArc::getArcShape()
 {
   if(!myStart.get() || !myEnd.get() || !myCenter.get()) {
-    return AISObjectPtr();
+    return GeomShapePtr();
   }
 
   SketchPlugin_Sketch* aSketch = sketch();
   if(!aSketch) {
-    return AISObjectPtr();
+    return GeomShapePtr();
   }
 
-  std::shared_ptr<GeomAPI_Pnt> aStart = aSketch->to3D(myStart->x(), myStart->y());
-  std::shared_ptr<GeomAPI_Pnt> anEnd = aSketch->to3D(myEnd->x(), myEnd->y());
-  std::shared_ptr<GeomAPI_Pnt> aCenter = aSketch->to3D(myCenter->x(), myCenter->y());;
-
+  std::shared_ptr<GeomAPI_Pnt> aCenter(aSketch->to3D(myCenter->x(), myCenter->y()));
+  std::shared_ptr<GeomAPI_Pnt> aStart(aSketch->to3D(myStart->x(), myStart->y()));
+  std::shared_ptr<GeomAPI_Pnt> anEnd(aSketch->to3D(myEnd->x(), myEnd->y()));
   std::shared_ptr<GeomDataAPI_Dir> aNDir =
-      std::dynamic_pointer_cast<GeomDataAPI_Dir>(
-          aSketch->data()->attribute(SketchPlugin_Sketch::NORM_ID()));
-  std::shared_ptr<GeomAPI_Dir> aNormal = aNDir->dir();
+    std::dynamic_pointer_cast<GeomDataAPI_Dir>(aSketch->attribute(SketchPlugin_Sketch::NORM_ID()));
+  std::shared_ptr<GeomAPI_Dir> aNormal(new GeomAPI_Dir(aNDir->x(), aNDir->y(), aNDir->z()));
+
   GeomShapePtr anArcShape = boolean(REVERSED_ID())->value() ?
       GeomAlgoAPI_EdgeBuilder::lineCircleArc(aCenter, anEnd, aStart, aNormal)
     : GeomAlgoAPI_EdgeBuilder::lineCircleArc(aCenter, aStart, anEnd, aNormal);
+
+  return anArcShape;
+}
+
+AISObjectPtr SketchPlugin_MacroArc::getAISObject(AISObjectPtr thePrevious)
+{
+  if(!myStart.get() || !myEnd.get() || !myCenter.get()) {
+    return AISObjectPtr();
+  }
+
+  SketchPlugin_Sketch* aSketch = sketch();
+  if(!aSketch) {
+    return AISObjectPtr();
+  }
+
+  GeomShapePtr anArcShape = getArcShape();
+  std::shared_ptr<GeomAPI_Pnt> aCenter = aSketch->to3D(myCenter->x(), myCenter->y());;
   GeomShapePtr aCenterPointShape = GeomAlgoAPI_PointBuilder::vertex(aCenter);
 
   if(!anArcShape.get() || !aCenterPointShape.get()) {
index 9fb6bdb3f1bcbf71d8ff517cce9b97ff9a38d601..cc49b0e0233db56c82a7bc39934d337b33b95adc 100644 (file)
@@ -192,6 +192,9 @@ class SketchPlugin_MacroArc: public SketchPlugin_SketchEntity,
   /// Use plugin manager for features creation.
   SketchPlugin_MacroArc();
 
+  /// Returns shape of arc.
+  GeomShapePtr getArcShape();
+
 private:
   /// Set fields for center, start and end points
   void fillByCenterAndTwoPassed();
index c09102540a14aec4501020a33c1719fe1e17a91e..05ba4c5013be735bc688e289d5181bf33b650e22 100644 (file)
@@ -96,6 +96,10 @@ SketchPlugin_Plugin::SketchPlugin_Plugin()
                               new SketchPlugin_CirclePassedPointValidator);
   aFactory->registerValidator("SketchPlugin_ThirdPointValidator",
                               new SketchPlugin_ThirdPointValidator);
+  aFactory->registerValidator("SketchPlugin_ArcEndPointValidator",
+                              new SketchPlugin_ArcEndPointValidator);
+  aFactory->registerValidator("SketchPlugin_ArcEndPointIntersectionValidator",
+                              new SketchPlugin_ArcEndPointIntersectionValidator);
 
   // register this plugin
   ModelAPI_Session::get()->registerPlugin(this);
index 00298e2975582f4dba2a862d35139ca88124909e..398827f61b2867a51a21f83f7f58063d9f1d42c1 100755 (executable)
@@ -41,6 +41,8 @@
 #include <ModelGeomAlgo_Point2D.h>
 #include <ModelGeomAlgo_Shape.h>
 
+#include <GeomAlgoAPI_ShapeTools.h>
+
 #include <GeomAPI_Circ.h>
 #include <GeomAPI_Dir2d.h>
 #include <GeomAPI_Lin.h>
@@ -1278,3 +1280,93 @@ bool SketchPlugin_ThirdPointValidator::arePointsNotSeparated(
     theError = aErrorPointsApart;
   return isOk;
 }
+
+bool SketchPlugin_ArcEndPointValidator::isValid(
+    const AttributePtr& theAttribute,
+    const std::list<std::string>& theArguments,
+    Events_InfoMessage& theError) const
+{
+  FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
+  AttributeRefAttrPtr anEndPointRef = aFeature->refattr(theArguments.front());
+
+  if(!anEndPointRef.get()) {
+    return true;
+  }
+
+  if(!anEndPointRef->isInitialized()) {
+    return true;
+  }
+
+  if(anEndPointRef->attr().get()) {
+    return false;
+  }
+
+  ObjectPtr anObject = anEndPointRef->object();
+  ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
+  if(aResult.get()) {
+    GeomShapePtr aShape = aResult->shape();
+    if(aShape.get() && aShape->isVertex()) {
+      return false;
+    }
+  }
+
+  aFeature = ModelAPI_Feature::feature(anObject);
+  if(aFeature.get()) {
+    if(aFeature->getKind() == SketchPlugin_Point::ID()) {
+      return false;
+    }
+  }
+
+  return true;
+}
+
+bool SketchPlugin_ArcEndPointIntersectionValidator::isValid(
+    const AttributePtr& theAttribute,
+    const std::list<std::string>& theArguments,
+    Events_InfoMessage& theError) const
+{
+  std::shared_ptr<SketchPlugin_MacroArc> anArcFeature =
+      std::dynamic_pointer_cast<SketchPlugin_MacroArc>(theAttribute->owner());
+  AttributeRefAttrPtr anEndPointRef = anArcFeature->refattr(theArguments.front());
+
+  if(!anEndPointRef.get()) {
+    return true;
+  }
+
+  if(!anEndPointRef->isInitialized()) {
+    return true;
+  }
+
+  GeomShapePtr anArcShape = anArcFeature->getArcShape();
+
+  if(!anArcShape.get() || anArcShape->isNull()) {
+    return true;
+  }
+
+  ObjectPtr anObject = anEndPointRef->object();
+  ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
+  if(aResult.get()) {
+    GeomShapePtr aShape = aResult->shape();
+    if(aShape.get() && !aShape->isNull()) {
+      return GeomAlgoAPI_ShapeTools::isShapesIntersects(anArcShape, aShape);
+    }
+  }
+
+  FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(anObject);
+  if(aSelectedFeature.get()) {
+    std::list<ResultPtr> aResults = aSelectedFeature->results();
+    for(std::list<ResultPtr>::const_iterator anIt = aResults.cbegin();
+        anIt != aResults.cend();
+        ++anIt)
+    {
+      GeomShapePtr aShape = (*anIt)->shape();
+      if(aShape.get() && !aShape->isNull()) {
+        if(GeomAlgoAPI_ShapeTools::isShapesIntersects(anArcShape, aShape)) {
+          return true;
+        }
+      }
+    }
+  }
+
+  return false;
+}
index 441bd1793656215034a1b77db4b79416984035a3..bea581a48633f19fce2cdf3e00ce255ece07d8c2 100644 (file)
@@ -359,4 +359,40 @@ private:
                              Events_InfoMessage& theError) const;
 };
 
+/**\class SketchPlugin_ArcEndPointValidator
+ * \ingroup Validators
+ * \brief Validator for the end point of MacroArc feature.
+ *
+ * Checks that third point does not lie on a point.
+ */
+class SketchPlugin_ArcEndPointValidator: 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,
+                       Events_InfoMessage& theError) const;
+};
+
+/**\class SketchPlugin_ArcEndPointIntersectionValidator
+ * \ingroup Validators
+ * \brief Validator for the end point of MacroArc feature.
+ *
+ * Checks that third point does lie on edge which intersects arc.
+ */
+class SketchPlugin_ArcEndPointIntersectionValidator: 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,
+                       Events_InfoMessage& theError) const;
+};
+
 #endif
index f4d7261567815f7d3d8f4419e732c20f960a6afc..ec0ed952117a6fc6e7a84d7651b2e42acb5042a7 100644 (file)
                                      title="End point"
                                      tooltip="End point"
                                      accept_expressions="0"
-                                     enable_value="enable_by_preferences"/>
+                                     enable_value="enable_by_preferences">
+              <validator id="SketchPlugin_ArcEndPointValidator" parameters="end_point_ref"/>
+              <validator id="SketchPlugin_ArcEndPointIntersectionValidator" parameters="end_point_ref"/>
+            </sketch-2dpoint_selector>
             <validator id="GeomValidators_Different" parameters="center_point,start_point_1,end_point_1"/>
           </box>
           <box id="by_three_points"
                                      accept_expressions="0"
                                      enable_value="enable_by_preferences">
               <validator id="SketchPlugin_DifferentReference" parameters="start_point_ref,end_point_ref"/>
+              <validator id="SketchPlugin_ArcEndPointValidator" parameters="end_point_ref"/>
             </sketch-2dpoint_selector>
             <sketch-2dpoint_selector id="passed_point"
                                      reference_attribute="passed_point_ref"
                                      title="End point"
                                      tooltip="End point"
                                      accept_expressions="0"
-                                     enable_value="enable_by_preferences"/>
+                                     enable_value="enable_by_preferences">
+              <validator id="SketchPlugin_ArcEndPointValidator" parameters="end_point_ref"/>
+            </sketch-2dpoint_selector>
           </box>
         </toolbox>
         <labelvalue id="radius"