Edit feature: move call for all entities. There are bugs in moving.
return aMode;
}
+void PartSet_FeatureArcPrs::move(double theDeltaX, double theDeltaY)
+{
+ boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
+ if (!aData->isValid())
+ return;
+
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint1 =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(ARC_ATTR_CENTER));
+ aPoint1->setValue(aPoint1->x() + theDeltaX, aPoint1->y() + theDeltaY);
+
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint2 =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(ARC_ATTR_START));
+ aPoint2->setValue(aPoint2->x() + theDeltaX, aPoint2->y() + theDeltaY);
+
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint3 =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(ARC_ATTR_END));
+ aPoint1->setValue(aPoint3->x() + theDeltaX, aPoint3->y() + theDeltaY);
+}
+
+double PartSet_FeatureArcPrs::distanceToPoint(FeaturePtr theFeature,
+ double theX, double theY)
+{
+ double aDelta = 0;
+ if (!theFeature || theFeature->getKind() != getKind())
+ return aDelta;
+ boost::shared_ptr<GeomAPI_Pnt2d> aPoint2d(new GeomAPI_Pnt2d(theX, theY));
+
+
+ boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
+
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint1 =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(ARC_ATTR_CENTER));
+ aDelta = aPoint1->pnt()->distance(aPoint2d);
+
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint2 =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(ARC_ATTR_START));
+ aDelta = qMin(aDelta, aPoint2->pnt()->distance(aPoint2d));
+
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint3 =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(ARC_ATTR_END));
+ aDelta = qMin(aDelta, aPoint3->pnt()->distance(aPoint2d));
+
+ return aDelta;
+}
+
+boost::shared_ptr<GeomDataAPI_Point2D> PartSet_FeatureArcPrs::findPoint(FeaturePtr theFeature,
+ double theX, double theY)
+{
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint2D;
+ if (!theFeature || theFeature->getKind() != getKind())
+ return aPoint2D;
+
+ boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(ARC_ATTR_CENTER));
+ if (fabs(aPoint->x() - theX) < Precision::Confusion() &&
+ fabs(aPoint->y() - theY) < Precision::Confusion()) {
+ aPoint2D = aPoint;
+ }
+ if (!aPoint2D) {
+ aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(ARC_ATTR_START));
+ if (fabs(aPoint->x() - theX) < Precision::Confusion() &&
+ fabs(aPoint->y() - theY) < Precision::Confusion())
+ aPoint2D = aPoint;
+ }
+ if (!aPoint2D) {
+ aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(ARC_ATTR_END));
+ if (fabs(aPoint->x() - theX) < Precision::Confusion() &&
+ fabs(aPoint->y() - theY) < Precision::Confusion())
+ aPoint2D = aPoint;
+ }
+ return aPoint2D;
+}
+
void PartSet_FeatureArcPrs::projectPointOnArc(gp_Pnt& thePoint, Handle(V3d_View) theView,
double& theX, double& theY)
{
void projectPointOnArc(gp_Pnt& thePoint, Handle_V3d_View theView,
double& theX, double& theY);
+ /// \brief Move the full feature.
+ /// \param theDeltaX the delta for X coordinate is moved
+ /// \param theDeltaY the delta for Y coordinate is moved
+ virtual void move(double theDeltaX, double theDeltaY);
+
+ /// Return the distance between the feature and the point
+ /// \param theFeature feature object
+ /// \param theX the horizontal coordinate of the point
+ /// \param theX the vertical coordinate of the point
+ virtual double distanceToPoint(FeaturePtr theFeature, double theX, double theY);
+
+ /// Find a point in the line with given coordinates
+ /// \param theFeature the line feature
+ /// \param theX the horizontal point coordinate
+ /// \param theY the vertical point coordinate
+ virtual boost::shared_ptr<GeomDataAPI_Point2D> findPoint(FeaturePtr theFeature, double theX,
+ double theY);
+
protected:
/// Returns the feature point in the selection mode position.
/// \param theMode the current operation selection mode. The feature attribute depends on the mode
return aMode;
}
+void PartSet_FeatureCirclePrs::move(double theDeltaX, double theDeltaY)
+{
+ boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
+ if (!aData->isValid())
+ return;
+
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint1 =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(CIRCLE_ATTR_CENTER));
+ aPoint1->setValue(aPoint1->x() + theDeltaX, aPoint1->y() + theDeltaY);
+}
+
double PartSet_FeatureCirclePrs::distanceToPoint(FeaturePtr theFeature,
double theX, double theY)
{
/// \return next attribute selection mode
virtual PartSet_SelectionMode getNextMode(const std::string& theAttribute) const;
+ /// \brief Move the full feature.
+ /// \param theDeltaX the delta for X coordinate is moved
+ /// \param theDeltaY the delta for Y coordinate is moved
+ virtual void move(double theDeltaX, double theDeltaY);
+
/// Return the distance between the feature and the point
/// \param theFeature feature object
/// \param theX the horizontal coordinate of the point
/// \param theX the vertical coordinate of the point
- static double distanceToPoint(FeaturePtr theFeature, double theX, double theY);
+ virtual double distanceToPoint(FeaturePtr theFeature, double theX, double theY);
/// Find a point in the line with given coordinates
/// \param theFeature the line feature
/// \param theX the horizontal point coordinate
/// \param theY the vertical point coordinate
- static boost::shared_ptr<GeomDataAPI_Point2D> findPoint(FeaturePtr theFeature, double theX,
- double theY);
+ virtual boost::shared_ptr<GeomDataAPI_Point2D> findPoint(FeaturePtr theFeature, double theX,
+ double theY);
protected:
/// Returns the feature point in the selection mode position.
/// \param theMode the current operation selection mode. The feature attribute depends on the mode
return aMode;
}
+void PartSet_FeatureLinePrs::move(double theDeltaX, double theDeltaY)
+{
+ boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
+ if (!aData->isValid())
+ return;
+
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint1 =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_START));
+ aPoint1->setValue(aPoint1->x() + theDeltaX, aPoint1->y() + theDeltaY);
+
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint2 =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_END));
+ aPoint2->setValue(aPoint2->x() + theDeltaX, aPoint2->y() + theDeltaY);
+}
+
void PartSet_FeatureLinePrs::projectPointOnLine(FeaturePtr theFeature,
const PartSet_SelectionMode& theMode,
const gp_Pnt& thePoint, Handle(V3d_View) theView,
double theX, double theY)
{
double aDelta = 0;
- if (!theFeature || theFeature->getKind() != SKETCH_LINE_KIND)
+ if (!theFeature || theFeature->getKind() != getKind())
return aDelta;
boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
double theX, double theY)
{
boost::shared_ptr<GeomDataAPI_Point2D> aPoint2D;
- if (!theFeature || theFeature->getKind() != SKETCH_LINE_KIND)
+ if (!theFeature || theFeature->getKind() != getKind())
return aPoint2D;
boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
- aPoint2D = PartSet_FeatureLinePrs::findPoint(theFeature, theX, theY);
-
boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_START));
if (fabs(aPoint->x() - theX) < Precision::Confusion() &&
/// \return next attribute selection mode
virtual PartSet_SelectionMode getNextMode(const std::string& theAttribute) const;
+ /// \brief Move the full feature.
+ /// \param theDeltaX the delta for X coordinate is moved
+ /// \param theDeltaY the delta for Y coordinate is moved
+ virtual void move(double theDeltaX, double theDeltaY);
/// Project the point on a feature
/// \param theFeature the feature to be projected on
/// \param theFeature feature object
/// \param theX the horizontal coordinate of the point
/// \param theX the vertical coordinate of the point
- static double distanceToPoint(FeaturePtr theFeature, double theX, double theY);
+ virtual double distanceToPoint(FeaturePtr theFeature, double theX, double theY);
/// Find a point in the line with given coordinates
/// \param theFeature the line feature
/// \param theX the horizontal point coordinate
/// \param theY the vertical point coordinate
- static boost::shared_ptr<GeomDataAPI_Point2D> findPoint(FeaturePtr theFeature, double theX,
- double theY);
+ virtual boost::shared_ptr<GeomDataAPI_Point2D> findPoint(FeaturePtr theFeature, double theX,
+ double theY);
protected:
/// Initializes current feature by the given
return aMode;
}
+void PartSet_FeaturePointPrs::move(double theDeltaX, double theDeltaY)
+{
+ boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
+ if (!aData->isValid())
+ return;
+
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint1 =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(POINT_ATTR_COORD));
+ aPoint1->setValue(aPoint1->x() + theDeltaX, aPoint1->y() + theDeltaY);
+}
+
double PartSet_FeaturePointPrs::distanceToPoint(FeaturePtr theFeature,
double theX, double theY)
{
/// \return next attribute selection mode
virtual PartSet_SelectionMode getNextMode(const std::string& theAttribute) const;
+ /// \brief Move the full feature.
+ /// \param theDeltaX the delta for X coordinate is moved
+ /// \param theDeltaY the delta for Y coordinate is moved
+ virtual void move(double theDeltaX, double theDeltaY);
+
/// Return the distance between the feature and the point
/// \param theFeature feature object
/// \param theX the horizontal coordinate of the point
/// \param theX the vertical coordinate of the point
- static double distanceToPoint(FeaturePtr theFeature, double theX, double theY);
+ virtual double distanceToPoint(FeaturePtr theFeature, double theX, double theY);
/// Find a point in the line with given coordinates
/// \param theFeature the line feature
/// \param theX the horizontal point coordinate
/// \param theY the vertical point coordinate
- static boost::shared_ptr<GeomDataAPI_Point2D> findPoint(FeaturePtr theFeature, double theX,
+ virtual boost::shared_ptr<GeomDataAPI_Point2D> findPoint(FeaturePtr theFeature, double theX,
double theY);
protected:
/// \return next attribute selection mode
virtual PartSet_SelectionMode getNextMode(const std::string& theAttribute) const = 0;
+ /// \brief Move the full feature.
+ /// \param theDeltaX the delta for X coordinate is moved
+ /// \param theDeltaY the delta for Y coordinate is moved
+ virtual void move(double theDeltaX, double theDeltaY) = 0;
+
+ /// Return the distance between the feature and the point
+ /// \param theFeature feature object
+ /// \param theX the horizontal coordinate of the point
+ /// \param theX the vertical coordinate of the point
+ virtual double distanceToPoint(FeaturePtr theFeature, double theX, double theY) = 0;
+
+ /// Find a point in the line with given coordinates
+ /// \param theFeature the line feature
+ /// \param theX the horizontal point coordinate
+ /// \param theY the vertical point coordinate
+ virtual boost::shared_ptr<GeomDataAPI_Point2D> findPoint(FeaturePtr theFeature, double theX,
+ double theY) = 0;
+
/// Creates constrains of the current
/// \param theX the horizontal coordnate of the point
/// \param theY the vertical coordnate of the point
double aDeltaX = aX - aCurX;
double aDeltaY = anY - aCurY;
- moveLinePoint(feature(), aDeltaX, aDeltaY, LINE_ATTR_START);
- moveLinePoint(feature(), aDeltaX, aDeltaY, LINE_ATTR_END);
+ PartSet_Tools::moveFeature(feature(), aDeltaX, aDeltaY);
std::list<XGUI_ViewerPrs>::const_iterator anIt = myFeatures.begin(), aLast = myFeatures.end();
for (; anIt != aLast; anIt++) {
FeaturePtr aFeature = (*anIt).feature();
if (!aFeature || aFeature == feature())
continue;
- moveLinePoint(aFeature, aDeltaX, aDeltaY, LINE_ATTR_START);
- moveLinePoint(aFeature, aDeltaX, aDeltaY, LINE_ATTR_END);
+ PartSet_Tools::moveFeature(aFeature, aDeltaX, aDeltaY);
}
}
sendFeatures();
return FeaturePtr();
}
-void PartSet_OperationEditFeature::moveLinePoint(FeaturePtr theFeature,
- double theDeltaX, double theDeltaY,
- const std::string& theAttribute)
-{
- if (!theFeature || theFeature->getKind() != SKETCH_LINE_KIND)
- return;
-
- boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
- if (!aData->isValid())
- return;
- boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(theAttribute));
-
- aPoint->setValue(aPoint->x() + theDeltaX, aPoint->y() + theDeltaY);
-}
-
void PartSet_OperationEditFeature::sendFeatures()
{
static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_MOVED);
/// \param isRestoreSelection the state whether the selected objects should be reselected
void blockSelection(bool isBlocked, const bool isRestoreSelection = true);
- /// \brief Save the point to the line.
- /// \param theFeature the source feature
- /// \param theDeltaX the delta for X coordinate is moved
- /// \param theDeltaY the delta for Y coordinate is moved
- /// \param theAttribute the start or end attribute of the line
- void moveLinePoint(FeaturePtr theFeature,
- double theDeltaX, double theDeltaY,
- const std::string& theAttribute);
/// Sends the features
void sendFeatures();
double PartSet_Tools::distanceToPoint(FeaturePtr theFeature,
double theX, double theY)
{
+ boost::shared_ptr<PartSet_FeaturePrs> aFeaturePrs = PartSet_Tools::createFeaturePrs(
+ theFeature->getKind(), FeaturePtr(), theFeature);
double aDelta = 0;
- std::string aKind = theFeature->getKind();
- if (aKind == PartSet_FeatureLinePrs::getKind()) {
- aDelta = PartSet_FeatureLinePrs::distanceToPoint(theFeature, theX, theY);
- }
- else if (aKind == PartSet_FeaturePointPrs::getKind()) {
- aDelta = PartSet_FeaturePointPrs::distanceToPoint(theFeature, theX, theY);
- }
- else if (aKind == PartSet_FeatureCirclePrs::getKind()) {
- aDelta = PartSet_FeatureCirclePrs::distanceToPoint(theFeature, theX, theY);
- }
+ if (aFeaturePrs)
+ aDelta = aFeaturePrs->distanceToPoint(theFeature, theX, theY);
return aDelta;
}
+void PartSet_Tools::moveFeature(FeaturePtr theFeature, double theDeltaX, double theDeltaY)
+{
+ if (!theFeature)
+ return;
+
+ boost::shared_ptr<PartSet_FeaturePrs> aFeaturePrs = PartSet_Tools::createFeaturePrs(
+ theFeature->getKind(), FeaturePtr(), theFeature);
+ if (aFeaturePrs)
+ aFeaturePrs->move(theDeltaX, theDeltaY);
+}
+
boost::shared_ptr<ModelAPI_Document> PartSet_Tools::document()
{
return ModelAPI_PluginManager::get()->rootDocument();
boost::shared_ptr<GeomDataAPI_Point2D> PartSet_Tools::findPoint(FeaturePtr theFeature,
double theX, double theY)
{
- boost::shared_ptr<GeomDataAPI_Point2D> aPoint2D;
- if (!theFeature)
- return aPoint2D;
+ boost::shared_ptr<PartSet_FeaturePrs> aFeaturePrs = PartSet_Tools::createFeaturePrs(
+ theFeature->getKind(), FeaturePtr(), theFeature);
- std::string aKind = theFeature->getKind();
- if (aKind == PartSet_FeatureLinePrs::getKind()) {
- aPoint2D = PartSet_FeatureLinePrs::findPoint(theFeature, theX, theY);
- }
- else if (aKind == PartSet_FeaturePointPrs::getKind()) {
- aPoint2D = PartSet_FeaturePointPrs::findPoint(theFeature, theX, theY);
- }
- else if (aKind == PartSet_FeatureCirclePrs::getKind()) {
- aPoint2D = PartSet_FeatureCirclePrs::findPoint(theFeature, theX, theY);
- }
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint2D;
+ if (aFeaturePrs)
+ aPoint2D = aFeaturePrs->findPoint(theFeature, theX, theY);
return aPoint2D;
}
FeaturePtr theSketch,
FeaturePtr theFeature = FeaturePtr());
-
/// Returns a feature that is under the mouse point
/// \param thePoint a screen point
/// \param theView a 3D view
static FeaturePtr nearestFeature(QPoint thePoint, Handle_V3d_View theView, FeaturePtr theSketch,
const std::list<XGUI_ViewerPrs>& theFeatures);
+ /// \brief Move the feature.
+ /// \param theFeature the source feature
+ /// \param theDeltaX the delta for X coordinate is moved
+ /// \param theDeltaY the delta for Y coordinate is moved
+ static void moveFeature(FeaturePtr theFeature, double theDeltaX, double theDeltaY);
+
/// Returns pointer to the root document.
static boost::shared_ptr<ModelAPI_Document> document();