Salome HOME
Issue #738 select point by mouse change predefined coordinates of connected object
authornds <nds@opencascade.com>
Tue, 1 Sep 2015 09:09:16 +0000 (12:09 +0300)
committernds <nds@opencascade.com>
Tue, 1 Sep 2015 09:09:40 +0000 (12:09 +0300)
nestedFeature, distance2Point are obsolete.

16 files changed:
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_Tools.cpp
src/PartSet/PartSet_Tools.h
src/PartSet/PartSet_WidgetPoint2d.cpp
src/SketchPlugin/SketchPlugin_Arc.cpp
src/SketchPlugin/SketchPlugin_Arc.h
src/SketchPlugin/SketchPlugin_Circle.cpp
src/SketchPlugin/SketchPlugin_Circle.h
src/SketchPlugin/SketchPlugin_ConstraintBase.cpp
src/SketchPlugin/SketchPlugin_ConstraintBase.h
src/SketchPlugin/SketchPlugin_ConstraintDistance.h
src/SketchPlugin/SketchPlugin_Feature.h
src/SketchPlugin/SketchPlugin_Line.h
src/SketchPlugin/SketchPlugin_Point.cpp
src/SketchPlugin/SketchPlugin_Point.h
src/SketchPlugin/SketchPlugin_Sketch.h

index e339b8cda9bea21623b53ca72d1704f485e29b07..39ace8d4c22a143288a7046eec3ed1b0725dc3c2 100755 (executable)
@@ -526,10 +526,9 @@ void PartSet_Module::onNoMoreWidgets()
       XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
       XGUI_Workshop* aWorkshop = aConnector->workshop();
       XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
+      // do nothing if the feature can not be applyed
       if (anOpMgr->isApplyEnabled())
         anOperation->commit();
-      else
-        anOperation->abort();
     }
   }
 }
index ebd22fdef4bb2f141db3a920f0634712224e269f..8a4c158f3935ca4a311730804b968411d35990c2 100755 (executable)
@@ -178,68 +178,6 @@ std::shared_ptr<GeomAPI_Pnt> PartSet_Tools::convertTo3D(const double theX, const
   return aPnt2d->to3D(aC->pnt(), aX->dir(), aY);
 }
 
-ObjectPtr PartSet_Tools::nearestFeature(QPoint thePoint, Handle_V3d_View theView,
-                                        FeaturePtr theSketch,
-                                        const QList<ModuleBase_ViewerPrs>& theSelected,
-                                        const QList<ModuleBase_ViewerPrs>& theHighlighted)
-{
-  // firstly it finds the feature in the list of highlight
-  ObjectPtr aDeltaObject  = nearestFeature(thePoint, theView, theSketch, theHighlighted);
-  if (!aDeltaObject)
-    // secondly it finds the feature in the list of selected objects
-    aDeltaObject  = nearestFeature(thePoint, theView, theSketch, theSelected);
-
-  return aDeltaObject;
-}
-
-ObjectPtr PartSet_Tools::nearestFeature(QPoint thePoint, Handle_V3d_View theView,
-                                        FeaturePtr theSketch,
-                                        const QList<ModuleBase_ViewerPrs>& thePresentations)
-{
-  ObjectPtr aDeltaObject;
-
-  CompositeFeaturePtr aSketch = 
-      std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(theSketch);
-  // 1. find it in the selected list by the selected point
-  if (!aDeltaObject) {
-    double aX, anY;
-    gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(thePoint, theView);
-    PartSet_Tools::convertTo2D(aPoint, theSketch, theView, aX, anY);
-
-    FeaturePtr aFeature;
-    double aMinDelta = -1;
-    ModuleBase_ViewerPrs aPrs;
-    foreach (ModuleBase_ViewerPrs aPrs, thePresentations) {
-      if (!aPrs.object())
-        continue;
-      FeaturePtr aFeature = ModelAPI_Feature::feature(aPrs.object());
-      std::shared_ptr<SketchPlugin_Feature> aSketchFeature = std::dynamic_pointer_cast<
-          SketchPlugin_Feature>(aFeature);
-      if (!aSketchFeature || !aSketch->isSub(aSketchFeature))
-        continue;
-
-      double aDelta = aSketchFeature->distanceToPoint(
-          std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(aX, anY)));
-      if (aMinDelta < 0 || aMinDelta > aDelta) {
-        aMinDelta = aDelta;
-        // TODO aDeltaObject = aPrs.result();
-      }
-    }
-  }
-  // 2. if the object is not found, returns the first selected sketch feature
-  if (!aDeltaObject && thePresentations.size() > 0) {
-    // there can be some highlighted objects, e.g. a result of boolean operation and a sketch point
-    foreach (ModuleBase_ViewerPrs aPrs, thePresentations) {
-      if (!aPrs.object())
-        continue;
-      FeaturePtr aFeature = ModelAPI_Feature::feature(aPrs.object());
-      if (aFeature && aSketch->isSub(aFeature))
-        aDeltaObject = aPrs.object();
-    }
-  }
-  return aDeltaObject;
-}
-
 std::shared_ptr<ModelAPI_Document> PartSet_Tools::document()
 {
   return ModelAPI_Session::get()->moduleDocument();
index 9578493085a83eee3d5be3a29de3c451a77eeb41..ad5fbcbcfc0dde05bf0d3c8ba25088ab373ce6e3 100755 (executable)
@@ -68,19 +68,6 @@ class PARTSET_EXPORT PartSet_Tools
   /// \param theSketch the sketch feature
   static std::shared_ptr<GeomAPI_Pnt> convertTo3D(const double theX, const double theY, FeaturePtr theSketch);
 
-  /// Returns an object that is under the mouse point. Firstly it checks the highlighting,
-  /// if it exists, the first object is returned. Secondly, there is an iteration on
-  /// the selected list to find the point. Thirdly, if the object is not found under the
-  /// the point, the first selected object is returned.
-  /// \param thePoint a screen point
-  /// \param theView a 3D view
-  /// \param theSketch the sketch feature
-  /// \param theSelected the list of selected presentations
-  /// \param theHighlighted the list of highlighted presentations
-  static ObjectPtr nearestFeature(QPoint thePoint, Handle_V3d_View theView, FeaturePtr theSketch,
-                                  const QList<ModuleBase_ViewerPrs>& theSelected,
-                                  const QList<ModuleBase_ViewerPrs>& theHighlighted);
-
   /// Returns pointer to the root document.
   static std::shared_ptr<ModelAPI_Document> document();
 
@@ -234,19 +221,6 @@ class PARTSET_EXPORT PartSet_Tools
   */
   static void findCoincidences(FeaturePtr theStartCoin, QList<FeaturePtr>& theList,
                                std::string theAttr);
-
-protected:
-  /// Returns an object that is under the mouse point. Firstly it checks the highlighting,
-  /// if it exists, the first object is returned. Secondly, there is an iteration on
-  /// the selected list to find the point. Thirdly, if the object is not found under the
-  /// the point, the first selected object is returned.
-  /// \param thePoint a screen point
-  /// \param theView a 3D view
-  /// \param theSketch the sketch feature
-  /// \param thePresentations the list of presentations
-  static ObjectPtr nearestFeature(QPoint thePoint, Handle_V3d_View theView, FeaturePtr theSketch,
-                                  const QList<ModuleBase_ViewerPrs>& thePresentations);
-
 };
 
 #endif
index 4add87d9dd6feb2f44507fd05002d2c0ce473aea..31a972e2fad97df0014f9714575072683366f8f7 100644 (file)
@@ -327,7 +327,30 @@ void PartSet_WidgetPoint2D::onMouseRelease(ModuleBase_IViewWindow* theWnd, QMous
     double aX, aY;
     bool isProcessed = false;
     if (getPoint2d(aView, aShape, aX, aY)) {
-      PartSet_Tools::setConstraints(mySketch, feature(), attributeID(),aX, aY);
+      bool aFeatureContainsPoint = false;
+  
+      std::shared_ptr<GeomAPI_Pnt2d> aPnt2d = 
+                                       std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(aX, aY));
+      std::list<AttributePtr> anAttributes =
+                                    myFeature->data()->attributes(GeomDataAPI_Point2D::typeId());
+      std::list<AttributePtr>::iterator anIter = anAttributes.begin();
+      for(; anIter != anAttributes.end(); anIter++) {
+        AttributePoint2DPtr aPoint2DAttribute =
+          std::dynamic_pointer_cast<GeomDataAPI_Point2D>(*anIter);
+        if (aPoint2DAttribute.get()) {
+          aFeatureContainsPoint = aPoint2DAttribute->pnt()->isEqual(aPnt2d);
+        }
+      }
+      // when the point is selected, the coordinates of the point should be set into the attribute
+      setPoint(aX, aY);
+      // do not set a coincidence constraint in the attribute if the feature contains a point
+      // with the same coordinates. It is important for line creation in order to do not set
+      // the same constraints for the same points, oterwise the result line has zero length.
+      if (aFeatureContainsPoint)
+        return;
+      else {
+        PartSet_Tools::setConstraints(mySketch, feature(), attributeID(),aX, aY);
+      }
       isProcessed = true;
     } else if (aShape.ShapeType() == TopAbs_EDGE) {
       setConstraintWith(aObject);
index 312297733b333c670c75677006ee0d191e121d0e..04f2c922babe98d54245f40d28f4b9569af2c29f 100644 (file)
@@ -178,30 +178,6 @@ void SketchPlugin_Arc::move(double theDeltaX, double theDeltaY)
   aPoint1->move(theDeltaX, theDeltaY);
 }
 
-double SketchPlugin_Arc::distanceToPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
-{
-  double aDelta = 0;
-  std::shared_ptr<ModelAPI_Data> aData = data();
-
-  std::shared_ptr<GeomDataAPI_Point2D> aPoint1 = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
-      aData->attribute(SketchPlugin_Arc::CENTER_ID()));
-  aDelta = aPoint1->pnt()->distance(thePoint);
-
-  std::shared_ptr<GeomDataAPI_Point2D> aPoint2 = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
-      aData->attribute(SketchPlugin_Arc::START_ID()));
-  double aDistance = aPoint2->pnt()->distance(thePoint);
-  if (aDelta < aDistance)
-    aDelta = aDistance;
-
-  std::shared_ptr<GeomDataAPI_Point2D> aPoint3 = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
-      aData->attribute(SketchPlugin_Arc::END_ID()));
-  aDistance = aPoint3->pnt()->distance(thePoint);
-  if (aDelta < aDistance)
-    aDelta = aDistance;
-
-  return aDelta;
-}
-
 bool SketchPlugin_Arc::isFixed() {
   return data()->selection(EXTERNAL_ID())->context().get() != NULL;
 }
index efb66cf4f4f3508b69c2c23e73b2355dd403233e..4d2df1417c024db8c8dafe54bb1c7410d830033a 100644 (file)
@@ -82,10 +82,6 @@ class SketchPlugin_Arc : public SketchPlugin_SketchEntity, public GeomAPI_IPrese
   /// \param theDeltaY the delta for Y coordinate is moved
   SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY);
 
-  /// Return the distance between the feature and the point
-  /// \param thePoint the point
-  virtual double distanceToPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
-
   /// Use plugin manager for features creation
   SketchPlugin_Arc();
 
index 6bbb91c7349b38d406c4240dbb8fd18d880490d9..bf8a7d8d07b41186c1d6e62c7932970b7b7ce461 100644 (file)
@@ -83,15 +83,6 @@ void SketchPlugin_Circle::move(double theDeltaX, double theDeltaY)
   aPoint1->move(theDeltaX, theDeltaY);
 }
 
-double SketchPlugin_Circle::distanceToPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
-{
-  std::shared_ptr<ModelAPI_Data> aData = data();
-  std::shared_ptr<GeomDataAPI_Point2D> aPoint = 
-    std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(CENTER_ID()));
-
-  return aPoint->pnt()->distance(thePoint);
-}
-
 bool SketchPlugin_Circle::isFixed() {
   return data()->selection(EXTERNAL_ID())->context().get() != NULL;
 }
index e4f705e76300fe56dee16c4ab913127247f1b77a..2edff8e39e43655b0fadac8627a1a52e64c48ed6 100644 (file)
@@ -68,10 +68,6 @@ class SketchPlugin_Circle : public SketchPlugin_SketchEntity
   /// \param theDeltaY the delta for Y coordinate is moved
   SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY);
 
-  /// Return the distance between the feature and the point
-  /// \param thePoint the point
-  virtual double distanceToPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
-
   /// Called on change of any argument-attribute of this object
   SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
 
index 63b7b8dd860eb582ff3aa24f33eb6d66266736f6..47ce81f8767b472e421772a257acdd999c0b3b11 100644 (file)
@@ -21,8 +21,3 @@ void SketchPlugin_ConstraintBase::move(const double theDeltaX, const double theD
 
 }
 
-double SketchPlugin_ConstraintBase::distanceToPoint(
-    const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
-{
-  return 0;
-}
index f6f6b07822cee2254a24221a45c956f4a87b401a..dffeed1a36d32afb8496f5bfd6c7b8e8a05ae8ee 100644 (file)
@@ -53,10 +53,6 @@ class SketchPlugin_ConstraintBase : public SketchPlugin_Constraint, public GeomA
   /// \param theDeltaY the delta for Y coordinate is moved
   SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY);
 
-  /// Return the distance between the feature and the point
-  /// \param thePoint the point
-  virtual double distanceToPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
-
  protected:
   /// \brief Use plugin manager for features creation
   SketchPlugin_ConstraintBase()
index e1d8a71abfe99f5c283bdce2939a64fa05a30e1c..cbd6ccf37f6ac2a5773f443744972c64149720ad 100644 (file)
@@ -67,12 +67,13 @@ class SketchPlugin_ConstraintDistance : public SketchPlugin_ConstraintBase
   /// \param theID identifier of changed attribute
   SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
 
-  /// Returns the current distance between the feature attributes
-  double calculateCurrentDistance();
-
   /// \brief Use plugin manager for features creation
   SketchPlugin_ConstraintDistance();
 
+protected:
+  /// Returns the current distance between the feature attributes
+  double calculateCurrentDistance();
+
 private:
   bool myFlyoutUpdate; ///< to avoid cyclic dependencies on automatic updates of flyout point
 };
index b8437dcbcaf7c3674d2399bc47ac87a5d4171668..2f386d18d4e63e8275bd0f32c7a897f3987b21b8 100644 (file)
@@ -18,7 +18,6 @@
 #include <Config_PropManager.h>
 
 class SketchPlugin_Sketch;
-class GeomAPI_Pnt2d;
 class Handle_AIS_InteractiveObject;
 
 /**\class SketchPlugin_Feature
@@ -46,10 +45,6 @@ class SketchPlugin_Feature : public ModelAPI_Feature
   /// \param theDeltaY the delta for Y coordinate is moved
   SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY) = 0;
 
-  /// Return the distance between the feature and the point
-  /// \param thePoint the point
-  virtual double distanceToPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint) = 0;
-
   /// Construction result is allways recomuted on the fly
   SKETCHPLUGIN_EXPORT virtual bool isPersistentResult() {return false;}
 
index f6d895974b981354c6eda92f0ba9c2f95f4a2dd8..eaa3330f3737ee5dbfdb63ee257a74c4e94b063d 100644 (file)
@@ -12,6 +12,8 @@
 #include <SketchPlugin_Sketch.h>
 #include <list>
 
+class GeomAPI_Pnt2d;
+
 /**\class SketchPlugin_Line
  * \ingroup Plugins
  * \brief Feature for creation of the new part in PartSet.
@@ -57,7 +59,7 @@ class SketchPlugin_Line : public SketchPlugin_SketchEntity
 
   /// Return the distance between the feature and the point
   /// \param thePoint the point
-  virtual double distanceToPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
+  double distanceToPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
 
   /// Called on change of any argument-attribute of this object
   SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
index d831982c1465bbcf4b20c395e617c07b566f39e2..cf718db760dd812324db95cf16a10a297494b29b 100644 (file)
@@ -63,15 +63,6 @@ void SketchPlugin_Point::move(double theDeltaX, double theDeltaY)
   aPoint1->move(theDeltaX, theDeltaY);
 }
 
-double SketchPlugin_Point::distanceToPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
-{
-  std::shared_ptr<ModelAPI_Data> aData = data();
-  std::shared_ptr<GeomDataAPI_Point2D> aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
-      aData->attribute(SketchPlugin_Point::COORD_ID()));
-
-  return aPoint->pnt()->distance(thePoint);
-}
-
 bool SketchPlugin_Point::isFixed() {
   return data()->selection(EXTERNAL_ID())->context().get() != NULL;
 }
index 4c774715757edc8463ee320102c7699d01f70ed7..59995ff4310aeb44edc72c2f950f4d3e09c0c119 100644 (file)
@@ -52,10 +52,6 @@ class SketchPlugin_Point : public SketchPlugin_SketchEntity
   /// \param theDeltaY the delta for Y coordinate is moved
   SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY);
 
-  /// Return the distance between the feature and the point
-  /// \param thePoint the point
-  virtual double distanceToPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
-
   /// Called on change of any argument-attribute of this object: for external point
   SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
 
index c9c474f734b14e4052942bffd4f10ccdcd252418..ab0bcd6ad9f0a31952c8e86ab4dd433edc535d78 100644 (file)
@@ -82,13 +82,6 @@ class SketchPlugin_Sketch : public ModelAPI_CompositeFeature, public GeomAPI_ICu
   {
   }
 
-  /// Return the distance between the feature and the point
-  /// \param thePoint the point
-  virtual double distanceToPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
-  {
-    return 0;
-  }
-
   /// Converts a 2D sketch space point into point in 3D space
   /// \param theX an X coordinate
   /// \param theY an Y coordinate