From: nds Date: Tue, 1 Sep 2015 09:09:16 +0000 (+0300) Subject: Issue #738 select point by mouse change predefined coordinates of connected object X-Git-Tag: V_1.4.0_beta4~172 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=3ada52ad6bce1f69571d9dea97f6631f155681d7;p=modules%2Fshaper.git Issue #738 select point by mouse change predefined coordinates of connected object nestedFeature, distance2Point are obsolete. --- diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index e339b8cda..39ace8d4c 100755 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -526,10 +526,9 @@ void PartSet_Module::onNoMoreWidgets() XGUI_ModuleConnector* aConnector = dynamic_cast(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(); } } } diff --git a/src/PartSet/PartSet_Tools.cpp b/src/PartSet/PartSet_Tools.cpp index ebd22fdef..8a4c158f3 100755 --- a/src/PartSet/PartSet_Tools.cpp +++ b/src/PartSet/PartSet_Tools.cpp @@ -178,68 +178,6 @@ std::shared_ptr 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& theSelected, - const QList& 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& thePresentations) -{ - ObjectPtr aDeltaObject; - - CompositeFeaturePtr aSketch = - std::dynamic_pointer_cast(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 aSketchFeature = std::dynamic_pointer_cast< - SketchPlugin_Feature>(aFeature); - if (!aSketchFeature || !aSketch->isSub(aSketchFeature)) - continue; - - double aDelta = aSketchFeature->distanceToPoint( - std::shared_ptr(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 PartSet_Tools::document() { return ModelAPI_Session::get()->moduleDocument(); diff --git a/src/PartSet/PartSet_Tools.h b/src/PartSet/PartSet_Tools.h index 957849308..ad5fbcbcf 100755 --- a/src/PartSet/PartSet_Tools.h +++ b/src/PartSet/PartSet_Tools.h @@ -68,19 +68,6 @@ class PARTSET_EXPORT PartSet_Tools /// \param theSketch the sketch feature static std::shared_ptr 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& theSelected, - const QList& theHighlighted); - /// Returns pointer to the root document. static std::shared_ptr document(); @@ -234,19 +221,6 @@ class PARTSET_EXPORT PartSet_Tools */ static void findCoincidences(FeaturePtr theStartCoin, QList& 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& thePresentations); - }; #endif diff --git a/src/PartSet/PartSet_WidgetPoint2d.cpp b/src/PartSet/PartSet_WidgetPoint2d.cpp index 4add87d9d..31a972e2f 100644 --- a/src/PartSet/PartSet_WidgetPoint2d.cpp +++ b/src/PartSet/PartSet_WidgetPoint2d.cpp @@ -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 aPnt2d = + std::shared_ptr(new GeomAPI_Pnt2d(aX, aY)); + std::list anAttributes = + myFeature->data()->attributes(GeomDataAPI_Point2D::typeId()); + std::list::iterator anIter = anAttributes.begin(); + for(; anIter != anAttributes.end(); anIter++) { + AttributePoint2DPtr aPoint2DAttribute = + std::dynamic_pointer_cast(*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); diff --git a/src/SketchPlugin/SketchPlugin_Arc.cpp b/src/SketchPlugin/SketchPlugin_Arc.cpp index 312297733..04f2c922b 100644 --- a/src/SketchPlugin/SketchPlugin_Arc.cpp +++ b/src/SketchPlugin/SketchPlugin_Arc.cpp @@ -178,30 +178,6 @@ void SketchPlugin_Arc::move(double theDeltaX, double theDeltaY) aPoint1->move(theDeltaX, theDeltaY); } -double SketchPlugin_Arc::distanceToPoint(const std::shared_ptr& thePoint) -{ - double aDelta = 0; - std::shared_ptr aData = data(); - - std::shared_ptr aPoint1 = std::dynamic_pointer_cast( - aData->attribute(SketchPlugin_Arc::CENTER_ID())); - aDelta = aPoint1->pnt()->distance(thePoint); - - std::shared_ptr aPoint2 = std::dynamic_pointer_cast( - aData->attribute(SketchPlugin_Arc::START_ID())); - double aDistance = aPoint2->pnt()->distance(thePoint); - if (aDelta < aDistance) - aDelta = aDistance; - - std::shared_ptr aPoint3 = std::dynamic_pointer_cast( - 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; } diff --git a/src/SketchPlugin/SketchPlugin_Arc.h b/src/SketchPlugin/SketchPlugin_Arc.h index efb66cf4f..4d2df1417 100644 --- a/src/SketchPlugin/SketchPlugin_Arc.h +++ b/src/SketchPlugin/SketchPlugin_Arc.h @@ -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& thePoint); - /// Use plugin manager for features creation SketchPlugin_Arc(); diff --git a/src/SketchPlugin/SketchPlugin_Circle.cpp b/src/SketchPlugin/SketchPlugin_Circle.cpp index 6bbb91c73..bf8a7d8d0 100644 --- a/src/SketchPlugin/SketchPlugin_Circle.cpp +++ b/src/SketchPlugin/SketchPlugin_Circle.cpp @@ -83,15 +83,6 @@ void SketchPlugin_Circle::move(double theDeltaX, double theDeltaY) aPoint1->move(theDeltaX, theDeltaY); } -double SketchPlugin_Circle::distanceToPoint(const std::shared_ptr& thePoint) -{ - std::shared_ptr aData = data(); - std::shared_ptr aPoint = - std::dynamic_pointer_cast(aData->attribute(CENTER_ID())); - - return aPoint->pnt()->distance(thePoint); -} - bool SketchPlugin_Circle::isFixed() { return data()->selection(EXTERNAL_ID())->context().get() != NULL; } diff --git a/src/SketchPlugin/SketchPlugin_Circle.h b/src/SketchPlugin/SketchPlugin_Circle.h index e4f705e76..2edff8e39 100644 --- a/src/SketchPlugin/SketchPlugin_Circle.h +++ b/src/SketchPlugin/SketchPlugin_Circle.h @@ -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& thePoint); - /// Called on change of any argument-attribute of this object SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID); diff --git a/src/SketchPlugin/SketchPlugin_ConstraintBase.cpp b/src/SketchPlugin/SketchPlugin_ConstraintBase.cpp index 63b7b8dd8..47ce81f87 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintBase.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintBase.cpp @@ -21,8 +21,3 @@ void SketchPlugin_ConstraintBase::move(const double theDeltaX, const double theD } -double SketchPlugin_ConstraintBase::distanceToPoint( - const std::shared_ptr& thePoint) -{ - return 0; -} diff --git a/src/SketchPlugin/SketchPlugin_ConstraintBase.h b/src/SketchPlugin/SketchPlugin_ConstraintBase.h index f6f6b0782..dffeed1a3 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintBase.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintBase.h @@ -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& thePoint); - protected: /// \brief Use plugin manager for features creation SketchPlugin_ConstraintBase() diff --git a/src/SketchPlugin/SketchPlugin_ConstraintDistance.h b/src/SketchPlugin/SketchPlugin_ConstraintDistance.h index e1d8a71ab..cbd6ccf37 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintDistance.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintDistance.h @@ -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 }; diff --git a/src/SketchPlugin/SketchPlugin_Feature.h b/src/SketchPlugin/SketchPlugin_Feature.h index b8437dcbc..2f386d18d 100644 --- a/src/SketchPlugin/SketchPlugin_Feature.h +++ b/src/SketchPlugin/SketchPlugin_Feature.h @@ -18,7 +18,6 @@ #include 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& thePoint) = 0; - /// Construction result is allways recomuted on the fly SKETCHPLUGIN_EXPORT virtual bool isPersistentResult() {return false;} diff --git a/src/SketchPlugin/SketchPlugin_Line.h b/src/SketchPlugin/SketchPlugin_Line.h index f6d895974..eaa3330f3 100644 --- a/src/SketchPlugin/SketchPlugin_Line.h +++ b/src/SketchPlugin/SketchPlugin_Line.h @@ -12,6 +12,8 @@ #include #include +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& thePoint); + double distanceToPoint(const std::shared_ptr& thePoint); /// Called on change of any argument-attribute of this object SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID); diff --git a/src/SketchPlugin/SketchPlugin_Point.cpp b/src/SketchPlugin/SketchPlugin_Point.cpp index d831982c1..cf718db76 100644 --- a/src/SketchPlugin/SketchPlugin_Point.cpp +++ b/src/SketchPlugin/SketchPlugin_Point.cpp @@ -63,15 +63,6 @@ void SketchPlugin_Point::move(double theDeltaX, double theDeltaY) aPoint1->move(theDeltaX, theDeltaY); } -double SketchPlugin_Point::distanceToPoint(const std::shared_ptr& thePoint) -{ - std::shared_ptr aData = data(); - std::shared_ptr aPoint = std::dynamic_pointer_cast( - aData->attribute(SketchPlugin_Point::COORD_ID())); - - return aPoint->pnt()->distance(thePoint); -} - bool SketchPlugin_Point::isFixed() { return data()->selection(EXTERNAL_ID())->context().get() != NULL; } diff --git a/src/SketchPlugin/SketchPlugin_Point.h b/src/SketchPlugin/SketchPlugin_Point.h index 4c7747157..59995ff43 100644 --- a/src/SketchPlugin/SketchPlugin_Point.h +++ b/src/SketchPlugin/SketchPlugin_Point.h @@ -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& thePoint); - /// Called on change of any argument-attribute of this object: for external point SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID); diff --git a/src/SketchPlugin/SketchPlugin_Sketch.h b/src/SketchPlugin/SketchPlugin_Sketch.h index c9c474f73..ab0bcd6ad 100644 --- a/src/SketchPlugin/SketchPlugin_Sketch.h +++ b/src/SketchPlugin/SketchPlugin_Sketch.h @@ -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& thePoint) - { - return 0; - } - /// Converts a 2D sketch space point into point in 3D space /// \param theX an X coordinate /// \param theY an Y coordinate