nestedFeature, distance2Point are obsolete.
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();
}
}
}
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();
/// \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();
*/
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
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);
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;
}
/// \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();
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;
}
/// \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);
}
-double SketchPlugin_ConstraintBase::distanceToPoint(
- const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
-{
- return 0;
-}
/// \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()
/// \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
};
#include <Config_PropManager.h>
class SketchPlugin_Sketch;
-class GeomAPI_Pnt2d;
class Handle_AIS_InteractiveObject;
/**\class SketchPlugin_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;}
#include <SketchPlugin_Sketch.h>
#include <list>
+class GeomAPI_Pnt2d;
+
/**\class SketchPlugin_Line
* \ingroup Plugins
* \brief Feature for creation of the new part in PartSet.
/// 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);
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;
}
/// \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);
{
}
- /// 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