]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #698 - Distance constraint on circle - crash
authornds <natalia.donis@opencascade.com>
Tue, 30 Jun 2015 15:27:31 +0000 (18:27 +0300)
committernds <natalia.donis@opencascade.com>
Tue, 30 Jun 2015 15:27:59 +0000 (18:27 +0300)
12 files changed:
src/PartSet/PartSet_Tools.cpp
src/PartSet/PartSet_Tools.h
src/PartSet/PartSet_WidgetShapeSelector.cpp
src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp
src/SketchPlugin/SketchPlugin_ConstraintDistance.h
src/SketchPlugin/SketchPlugin_Sketch.cpp
src/SketchPlugin/SketchPlugin_Sketch.h
src/SketchPlugin/SketchPlugin_Validators.cpp
src/SketcherPrs/SketcherPrs_LengthDimension.cpp
src/SketcherPrs/SketcherPrs_LengthDimension.h
src/SketcherPrs/SketcherPrs_Tools.cpp
src/SketcherPrs/SketcherPrs_Tools.h

index 7fdc816a3e24f5167c46e6763dbb0e6272cf348a..f5dbff31826de43fb9ec1d77887839a8f57fc89f 100644 (file)
@@ -233,7 +233,7 @@ std::shared_ptr<ModelAPI_Document> PartSet_Tools::document()
   return ModelAPI_Session::get()->moduleDocument();
 }
 
-std::shared_ptr<GeomDataAPI_Point2D> PartSet_Tools::getFeaturePoint(FeaturePtr theFeature,
+/*std::shared_ptr<GeomDataAPI_Point2D> PartSet_Tools::getFeaturePoint(FeaturePtr theFeature,
                                                                       double theX, double theY)
 {
   std::shared_ptr<GeomAPI_Pnt2d> aClickedPoint = std::shared_ptr<GeomAPI_Pnt2d>(
@@ -251,7 +251,7 @@ std::shared_ptr<GeomDataAPI_Point2D> PartSet_Tools::getFeaturePoint(FeaturePtr t
   }
 
   return aFPoint;
-}
+}*/
 
 void PartSet_Tools::setFeatureValue(FeaturePtr theFeature, double theValue,
                                     const std::string& theAttribute)
@@ -327,7 +327,7 @@ void PartSet_Tools::createConstraint(CompositeFeaturePtr theSketch,
     aFeature->execute();
 }
 
-std::shared_ptr<GeomDataAPI_Point2D> PartSet_Tools::
+/*std::shared_ptr<GeomDataAPI_Point2D> PartSet_Tools::
   findAttributePoint(CompositeFeaturePtr theSketch, double theX, double theY,
   double theTolerance, const QList<FeaturePtr>& theIgnore)
 {
@@ -353,7 +353,7 @@ std::shared_ptr<GeomDataAPI_Point2D> PartSet_Tools::
     }
   }
   return std::shared_ptr<GeomDataAPI_Point2D>();
-}
+}*/
 
 
 void PartSet_Tools::setConstraints(CompositeFeaturePtr theSketch, FeaturePtr theFeature,
index 84b2311a6e7b5bf5e8377c7b19230dd7e9244961..1aaf66401d9856d6ff054e49187bbe82221566ff 100644 (file)
@@ -89,15 +89,15 @@ class PARTSET_EXPORT PartSet_Tools
   /// \param theY Y coordinate
   /// \param theTolerance tolerance
   /// \param theIgnore list of features which has to be ignored
-  static std::shared_ptr<GeomDataAPI_Point2D> findAttributePoint(CompositeFeaturePtr theSketch, 
-    double theX, double theY, double theTolerance, const QList<FeaturePtr>& theIgnore = QList<FeaturePtr>());
+  //static std::shared_ptr<GeomDataAPI_Point2D> findAttributePoint(CompositeFeaturePtr theSketch, 
+  //  double theX, double theY, double theTolerance, const QList<FeaturePtr>& theIgnore = QList<FeaturePtr>());
 
   /// Returns a point attribute of the feature by the coordinates if it is
   /// \param theFeature the feature
   /// \param theX the horizontal coordinate
   /// \param theY the vertical coordinate
-  static std::shared_ptr<GeomDataAPI_Point2D> getFeaturePoint(FeaturePtr theFeature,
-                                                                double theX, double theY);
+  //static std::shared_ptr<GeomDataAPI_Point2D> getFeaturePoint(FeaturePtr theFeature,
+  //                                                              double theX, double theY);
 
   /// \brief Save the double to the feature. If the attribute is double, it is filled.
   /// \param theFeature the feature
index 431f1e8a88db447743c393aaff943f3778878684..ae4a295126edfe8d2b31cfc2d765cae26dd90387 100644 (file)
@@ -28,6 +28,8 @@
 #include <SelectMgr_IndexedMapOfOwner.hxx>
 #include <StdSelect_BRepOwner.hxx>
 
+//#define DEBUG_EMPTY_SHAPE
+
 PartSet_WidgetShapeSelector::PartSet_WidgetShapeSelector(QWidget* theParent,
                                                          ModuleBase_IWorkshop* theWorkshop,
                                                          const Config_WidgetAPI* theData,
@@ -61,8 +63,21 @@ void PartSet_WidgetShapeSelector::setObject(ObjectPtr theSelectedObject, GeomSha
   std::shared_ptr<SketchPlugin_Feature> aSPFeature = 
           std::dynamic_pointer_cast<SketchPlugin_Feature>(aSelectedFeature);
   // Processing of sketch object
-  if (aSPFeature.get() != NULL && theShape.get())
+#ifdef DEBUG_EMPTY_SHAPE
+  if (aSPFeature.get() != NULL && theShape.get()) {
     setPointAttribute(theSelectedObject, theShape);
+#else
+  if (aSPFeature.get() != NULL) {
+    GeomShapePtr aShape = theShape;
+    if (!aShape.get()) {
+      ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theSelectedObject);
+      if (aResult.get()) {
+        aShape = aResult->shape();
+      }
+    }
+    setPointAttribute(theSelectedObject, aShape);
+#endif
+  }
   else
     ModuleBase_WidgetShapeSelector::setObject(theSelectedObject, theShape);
 }
index 11672f77a14bd074d4cf09d1a91ffdc1124a6bde..a119433d36f7f09a5b0cd801cd8811ce1f56505b 100644 (file)
@@ -80,10 +80,11 @@ bool SketchPlugin_ConstraintDistance::compute(const std::string& theAttributeId)
     return false;
 
   DataPtr aData = data();
+  std::shared_ptr<GeomAPI_Ax3> aPlane = SketchPlugin_Sketch::plane(sketch());
   std::shared_ptr<GeomDataAPI_Point2D> aPoint_A = SketcherPrs_Tools::getFeaturePoint(
-      aData, SketchPlugin_Constraint::ENTITY_A());
+      aData, SketchPlugin_Constraint::ENTITY_A(), aPlane);
   std::shared_ptr<GeomDataAPI_Point2D> aPoint_B = SketcherPrs_Tools::getFeaturePoint(
-      aData, SketchPlugin_Constraint::ENTITY_B());
+      aData, SketchPlugin_Constraint::ENTITY_B(), aPlane);
 
   std::shared_ptr<GeomAPI_Pnt2d> aPnt_A;
   std::shared_ptr<GeomAPI_Pnt2d> aPnt_B;
@@ -145,10 +146,11 @@ void SketchPlugin_ConstraintDistance::move(double theDeltaX, double theDeltaY)
 
   // Recalculate a shift of flyout point in terms of local coordinates
   std::shared_ptr<GeomAPI_XY> aDir(new GeomAPI_XY(theDeltaX, theDeltaY));
+  std::shared_ptr<GeomAPI_Ax3> aPlane = SketchPlugin_Sketch::plane(sketch());
   std::shared_ptr<GeomDataAPI_Point2D> aPointA = SketcherPrs_Tools::getFeaturePoint(
-      data(), SketchPlugin_Constraint::ENTITY_A());
+      data(), SketchPlugin_Constraint::ENTITY_A(), aPlane);
   std::shared_ptr<GeomDataAPI_Point2D> aPointB = SketcherPrs_Tools::getFeaturePoint(
-      data(), SketchPlugin_Constraint::ENTITY_B());
+      data(), SketchPlugin_Constraint::ENTITY_B(), aPlane);
 
   std::shared_ptr<GeomAPI_XY> aStartPnt;
   std::shared_ptr<GeomAPI_XY> aEndPnt;
@@ -185,15 +187,16 @@ void SketchPlugin_ConstraintDistance::move(double theDeltaX, double theDeltaY)
   myFlyoutUpdate = false;
 }
 
-double SketchPlugin_ConstraintDistance::calculateCurrentDistance() const
+double SketchPlugin_ConstraintDistance::calculateCurrentDistance()
 {
   double aDistance = -1.;
 
   std::shared_ptr<ModelAPI_Data> aData = data();
+  std::shared_ptr<GeomAPI_Ax3> aPlane = SketchPlugin_Sketch::plane(sketch());
   std::shared_ptr<GeomDataAPI_Point2D> aPointA =
-    SketcherPrs_Tools::getFeaturePoint(aData, SketchPlugin_Constraint::ENTITY_A());
+    SketcherPrs_Tools::getFeaturePoint(aData, SketchPlugin_Constraint::ENTITY_A(), aPlane);
   std::shared_ptr<GeomDataAPI_Point2D> aPointB =
-      SketcherPrs_Tools::getFeaturePoint(aData, SketchPlugin_Constraint::ENTITY_B());
+      SketcherPrs_Tools::getFeaturePoint(aData, SketchPlugin_Constraint::ENTITY_B(), aPlane);
 
   if (aPointA.get() && aPointB.get()) {  // both points
     aDistance = aPointA->pnt()->distance(aPointB->pnt());
@@ -241,10 +244,11 @@ void SketchPlugin_ConstraintDistance::attributeChanged(const std::string& theID)
         attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
     std::shared_ptr<GeomAPI_Pnt2d> aFlyoutPnt = aFlyoutAttr->pnt();
 
+    std::shared_ptr<GeomAPI_Ax3> aPlane = SketchPlugin_Sketch::plane(sketch());
     std::shared_ptr<GeomDataAPI_Point2D> aPointA = SketcherPrs_Tools::getFeaturePoint(
-        data(), SketchPlugin_Constraint::ENTITY_A());
+        data(), SketchPlugin_Constraint::ENTITY_A(), aPlane);
     std::shared_ptr<GeomDataAPI_Point2D> aPointB = SketcherPrs_Tools::getFeaturePoint(
-        data(), SketchPlugin_Constraint::ENTITY_B());
+        data(), SketchPlugin_Constraint::ENTITY_B(), aPlane);
 
     std::shared_ptr<GeomAPI_XY> aStartPnt;
     std::shared_ptr<GeomAPI_XY> aEndPnt;
index 370519bdaec0aa043ebcc832fbff05f2c45e905d..a1e315d2bc0246a0a75b8b7fec4d8aff02847b8f 100644 (file)
@@ -68,7 +68,7 @@ class SketchPlugin_ConstraintDistance : public SketchPlugin_ConstraintBase, publ
   SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
 
   /// Returns the current distance between the feature attributes
-  double calculateCurrentDistance() const;
+  double calculateCurrentDistance();
 
     /// Customize presentation of the feature
   virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
index 4c957c648792db67f8cee6994e6e9c1687c637b6..362e7f56f66956f60fccba2c0f3200e047cf4a20 100644 (file)
@@ -290,3 +290,17 @@ FeaturePtr SketchPlugin_Sketch::addUniqueNamedCopiedFeature(FeaturePtr theFeatur
 
   return aNewFeature;
 }
+
+std::shared_ptr<GeomAPI_Ax3> SketchPlugin_Sketch::plane(SketchPlugin_Sketch* theSketch)
+{
+  std::shared_ptr<ModelAPI_Data> aData = theSketch->data();
+
+  std::shared_ptr<GeomDataAPI_Point> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
+      aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
+  std::shared_ptr<GeomDataAPI_Dir> aDirX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+      aData->attribute(SketchPlugin_Sketch::DIRX_ID()));
+  std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+      aData->attribute(SketchPlugin_Sketch::NORM_ID()));
+
+  return std::shared_ptr<GeomAPI_Ax3>(new GeomAPI_Ax3(anOrigin->pnt(), aDirX->dir(), aNorm->dir()));
+}
index 2043f33f59eb640429dc48c6621bb59bf0c07e13..d4117c093c8e03a853ab66833170f2d35d78fc5d 100644 (file)
@@ -211,6 +211,10 @@ class SketchPlugin_Sketch : public ModelAPI_CompositeFeature, public GeomAPI_ICu
   static FeaturePtr addUniqueNamedCopiedFeature(FeaturePtr aFeature,
                                                 SketchPlugin_Sketch* theSketch);
 
+  /// Creates a plane of the sketch.
+  /// \param theSketch a sketch intance
+  static std::shared_ptr<GeomAPI_Ax3> plane(SketchPlugin_Sketch* theSketch);
+
   /// Customize presentation of the feature
   virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
                                      std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
index 9dfdb517155a23638c3f2808b20bcf96365c0cda..597f17d47a7e6d63a0df4f0d63a987e10099b801 100644 (file)
@@ -66,7 +66,12 @@ bool SketchPlugin_DistanceAttrValidator::isValid(
 
     FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
     // If it is a line then we have to check that first attribute id not a line
-    std::shared_ptr<GeomDataAPI_Point2D> aPoint = SketcherPrs_Tools::getFeaturePoint(aFeature->data(), aParamA);
+    std::shared_ptr<SketchPlugin_Feature> aSFeature =
+                            std::dynamic_pointer_cast<SketchPlugin_Feature>(theAttribute->owner());
+    SketchPlugin_Sketch* aSketch = aSFeature->sketch();
+    std::shared_ptr<GeomAPI_Ax3> aPlane = SketchPlugin_Sketch::plane(aSketch);
+    std::shared_ptr<GeomDataAPI_Point2D> aPoint = SketcherPrs_Tools::getFeaturePoint(
+                                                               aFeature->data(), aParamA, aPlane);
     if (aPoint)
       return true;
   }
index 39d5cfcd7b3690093ac2c62ee46a5852d00b9d95..6e3db92910475a765ffa4e187f4c19a55aadd42f 100644 (file)
@@ -90,7 +90,7 @@ void SketcherPrs_LengthDimension::Compute(const Handle(PrsMgr_PresentationManage
   AIS_LengthDimension::Compute(thePresentationManager, thePresentation, theMode);
 }
 
-bool SketcherPrs_LengthDimension::getPoints(gp_Pnt& thePnt1, gp_Pnt& thePnt2) const
+bool SketcherPrs_LengthDimension::getPoints(gp_Pnt& thePnt1, gp_Pnt& thePnt2)
 {
   DataPtr aData = myConstraint->data();
   if (myConstraint->getKind() == SketchPlugin_ConstraintLength::ID()) {
@@ -117,9 +117,9 @@ bool SketcherPrs_LengthDimension::getPoints(gp_Pnt& thePnt1, gp_Pnt& thePnt2) co
 
   } else if (myConstraint->getKind() == SketchPlugin_ConstraintDistance::ID()) {
     std::shared_ptr<GeomDataAPI_Point2D> aPoint_A = SketcherPrs_Tools::getFeaturePoint(
-        aData, SketchPlugin_Constraint::ENTITY_A());
+        aData, SketchPlugin_Constraint::ENTITY_A(), myPlane);
     std::shared_ptr<GeomDataAPI_Point2D> aPoint_B = SketcherPrs_Tools::getFeaturePoint(
-        aData, SketchPlugin_Constraint::ENTITY_B());
+        aData, SketchPlugin_Constraint::ENTITY_B(), myPlane);
 
     std::shared_ptr<GeomAPI_Pnt2d> aPnt_A;
     std::shared_ptr<GeomAPI_Pnt2d> aPnt_B;
index 5fde8d7aa0e094f1599a18f752c4d9c1b1138e81..703dc95770a615f0bf0e2471ce4d11a8d5daa90e 100644 (file)
@@ -43,7 +43,7 @@ protected:
     const Standard_Integer aMode);
 
 private:
-  bool getPoints(gp_Pnt& thePnt1, gp_Pnt& thePnt2) const;
+  bool getPoints(gp_Pnt& thePnt1, gp_Pnt& thePnt2);
 
   /// Constraint feature
   ModelAPI_Feature* myConstraint;
index 72cc8beeebcca35377c402a4b0efc7923c0924ca..912ea14467ee32d7c7b9fecd0c925422e72d2a6e 100644 (file)
 #include <GeomDataAPI_Point2D.h>
 #include <GeomAPI_Lin2d.h>
 
+#include <TopoDS.hxx>
+#include <TopoDS_Shape.hxx>
+#include <TopoDS_Vertex.hxx>
+
+#include <BRep_Tool.hxx>
+#include <Precision.hxx>
 
 namespace SketcherPrs_Tools {
 
@@ -66,9 +72,49 @@ std::shared_ptr<GeomAPI_Pnt2d> getPoint(ModelAPI_Feature* theFeature,
   return std::shared_ptr<GeomAPI_Pnt2d>();
 }
 
+//*************************************************************************************
+std::shared_ptr<GeomDataAPI_Point2D> findGeomPoint(ObjectPtr theObject, 
+                                    const TopoDS_Shape& theShape, 
+                                    const std::shared_ptr<GeomAPI_Ax3>& thePlane)
+{
+  std::shared_ptr<GeomDataAPI_Point2D> aGeomPoint;
+
+  FeaturePtr anObjectFeature = ModelAPI_Feature::feature(theObject);
+  if (anObjectFeature) {
+    if (theShape.ShapeType() == TopAbs_VERTEX) {
+      const TopoDS_Vertex& aShapeVertex = TopoDS::Vertex(theShape);
+      if (!aShapeVertex.IsNull())  {
+        gp_Pnt aShapePoint = BRep_Tool::Pnt(aShapeVertex);
+        std::shared_ptr<GeomAPI_Pnt> aShapeGeomPnt = std::shared_ptr<GeomAPI_Pnt>(
+            new GeomAPI_Pnt(aShapePoint.X(), aShapePoint.Y(), aShapePoint.Z()));
+
+        // find the given point in the feature attributes
+        std::list<AttributePtr> anObjectAttiributes = 
+          anObjectFeature->data()->attributes(GeomDataAPI_Point2D::typeId());
+        std::list<AttributePtr>::const_iterator anIt = anObjectAttiributes.begin(), 
+                                                aLast = anObjectAttiributes.end();
+        for (; anIt != aLast && !aGeomPoint; anIt++) {
+          std::shared_ptr<GeomDataAPI_Point2D> anAttributePoint = 
+            std::dynamic_pointer_cast<GeomDataAPI_Point2D>(*anIt);
+
+          std::shared_ptr<GeomAPI_Pnt> anAttributePnt = thePlane->to3D(anAttributePoint->x(),
+                                                                       anAttributePoint->y());
+          if (anAttributePnt.get() &&
+              anAttributePnt->distance(aShapeGeomPnt) < Precision::Confusion()) {
+            aGeomPoint = anAttributePoint;
+            break;
+          }
+        }
+      }
+    }
+  }
+  return aGeomPoint;
+}
+
 //*************************************************************************************
 std::shared_ptr<GeomDataAPI_Point2D> getFeaturePoint(DataPtr theData,
-                                                     const std::string& theAttribute)
+                                                     const std::string& theAttribute,
+                                                     const std::shared_ptr<GeomAPI_Ax3>& thePlane)
 {
   std::shared_ptr<GeomDataAPI_Point2D> aPointAttr;
 
@@ -78,15 +124,28 @@ std::shared_ptr<GeomDataAPI_Point2D> getFeaturePoint(DataPtr theData,
   FeaturePtr aFeature;
   std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = std::dynamic_pointer_cast<
       ModelAPI_AttributeRefAttr>(theData->attribute(theAttribute));
-  if (anAttr)
-    aFeature = ModelAPI_Feature::feature(anAttr->object());
-
-  if (aFeature && aFeature->getKind() == SketchPlugin_Point::ID())
-    aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
-        aFeature->data()->attribute(SketchPlugin_Point::COORD_ID()));
-
-  else if (anAttr->attr()) {
-    aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttr->attr());
+  if (anAttr) {
+    if (anAttr->isObject()) {
+      ObjectPtr anObject = anAttr->object();
+      aFeature = ModelAPI_Feature::feature(anObject);
+      if (aFeature && aFeature->getKind() == SketchPlugin_Point::ID()) {
+        aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+                     aFeature->data()->attribute(SketchPlugin_Point::COORD_ID()));
+      }
+      else {
+        ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
+        if (aRes.get()) {
+          GeomShapePtr aShape = aRes->shape();
+          if (aShape.get()) {
+            TopoDS_Shape aTDSShape = aShape->impl<TopoDS_Shape>();
+            aPointAttr = findGeomPoint(anObject, aTDSShape, thePlane);
+          }
+        }
+      }
+    }
+    else if (anAttr->attr()) {
+      aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttr->attr());
+    }
   }
   return aPointAttr;
 }
index ac014267e3f3f9b29bb2e44f7d223e4185902534..481e7d96d2eae703326284f11b9ca98e77105933 100644 (file)
@@ -56,7 +56,8 @@ enum SelectionModes {
 
   /// Obtain the point object from specified constraint parameter
   SKETCHERPRS_EXPORT std::shared_ptr<GeomDataAPI_Point2D> getFeaturePoint(DataPtr theData,
-                                                       const std::string& theAttribute);
+                                                       const std::string& theAttribute,
+                                                       const std::shared_ptr<GeomAPI_Ax3>& thePlane);
 
   SKETCHERPRS_EXPORT double getArrowSize();