Move all line specific information to FeatureLinePrs. Prepare FeaturePointPrs for the point feature.
PartSet.h
PartSet_Constants.h
PartSet_FeaturePrs.h
+ PartSet_FeatureLinePrs.h
+ PartSet_FeaturePointPrs.h
PartSet_Listener.h
PartSet_Module.h
PartSet_OperationConstraint.h
SET(PROJECT_SOURCES
PartSet_FeaturePrs.cpp
+ PartSet_FeatureLinePrs.cpp
+ PartSet_FeaturePointPrs.cpp
PartSet_Listener.cpp
PartSet_Module.cpp
PartSet_OperationConstraint.cpp
--- /dev/null
+// File: PartSet_FeaturePrs.h
+// Created: 04 Jun 2014
+// Author: Natalia ERMOLAEVA
+
+#include <PartSet_FeatureLinePrs.h>
+#include <PartSet_Tools.h>
+
+#include <SketchPlugin_Feature.h>
+#include <SketchPlugin_Sketch.h>
+#include <SketchPlugin_ConstraintCoincidence.h>
+#include <SketchPlugin_Line.h>
+#include <SketchPlugin_Constraint.h>
+
+#include <GeomDataAPI_Point2D.h>
+
+#include <ModelAPI_Data.h>
+#include <ModelAPI_Document.h>
+#include <ModelAPI_AttributeRefAttr.h>
+#include <ModelAPI_AttributeRefList.h>
+
+#include <Precision.hxx>
+
+using namespace std;
+
+PartSet_FeatureLinePrs::PartSet_FeatureLinePrs(FeaturePtr theSketch)
+: PartSet_FeaturePrs(theSketch)
+{
+}
+
+void PartSet_FeatureLinePrs::initFeature(FeaturePtr theFeature)
+{
+ if (feature() && theFeature)
+ {
+ // use the last point of the previous feature as the first of the new one
+ boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
+ boost::shared_ptr<GeomDataAPI_Point2D> anInitPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
+ (aData->attribute(LINE_ATTR_END));
+ PartSet_Tools::setFeaturePoint(feature(), anInitPoint->x(), anInitPoint->y(), LINE_ATTR_START);
+ PartSet_Tools::setFeaturePoint(feature(), anInitPoint->x(), anInitPoint->y(), LINE_ATTR_END);
+
+ aData = feature()->data();
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
+ (aData->attribute(LINE_ATTR_START));
+ PartSet_Tools::createConstraint(sketch(), anInitPoint, aPoint);
+ }
+}
+
+PartSet_SelectionMode PartSet_FeatureLinePrs::setPoint(double theX, double theY,
+ const PartSet_SelectionMode& theMode)
+{
+ PartSet_SelectionMode aMode = theMode;
+ switch (theMode)
+ {
+ case SM_FirstPoint: {
+ PartSet_Tools::setFeaturePoint(feature(), theX, theY, LINE_ATTR_START);
+ PartSet_Tools::setFeaturePoint(feature(), theX, theY, LINE_ATTR_END);
+ aMode = SM_SecondPoint;
+ }
+ break;
+ case SM_SecondPoint: {
+ PartSet_Tools::setFeaturePoint(feature(), theX, theY, LINE_ATTR_END);
+ aMode = SM_DonePoint;
+ }
+ break;
+ default:
+ break;
+ }
+ return aMode;
+}
+
+std::string PartSet_FeatureLinePrs::getAttribute(const PartSet_SelectionMode& theMode) const
+{
+ std::string aAttribute;
+ switch (theMode)
+ {
+ case SM_FirstPoint:
+ aAttribute = LINE_ATTR_START;
+ break;
+ case SM_SecondPoint:
+ aAttribute = LINE_ATTR_END;
+ break;
+ default:
+ break;
+ }
+ return aAttribute;
+}
+
+PartSet_SelectionMode PartSet_FeatureLinePrs::getNextMode(const std::string& theAttribute) const
+{
+ PartSet_SelectionMode aMode;
+
+ if (theAttribute == LINE_ATTR_START)
+ aMode = SM_SecondPoint;
+ else if (theAttribute == LINE_ATTR_END)
+ aMode = SM_DonePoint;
+ return aMode;
+}
+
+boost::shared_ptr<GeomDataAPI_Point2D> PartSet_FeatureLinePrs::featurePoint
+ (const PartSet_SelectionMode& theMode)
+{
+ std::string aPointArg;
+ switch (theMode)
+ {
+ case SM_FirstPoint:
+ aPointArg = LINE_ATTR_START;
+ break;
+ case SM_SecondPoint:
+ aPointArg = LINE_ATTR_END;
+ break;
+ default:
+ break;
+ }
+ boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
+ (aData->attribute(aPointArg));
+ return aPoint;
+}
--- /dev/null
+// File: PartSet_FeatureLinePrs.h
+// Created: 04 Jun 2014
+// Author: Natalia ERMOLAEVA
+
+#ifndef PartSet_FeatureLinePrs_H
+#define PartSet_FeatureLinePrs_H
+
+#include "PartSet.h"
+
+#include "PartSet_FeaturePrs.h"
+#include "PartSet_Constants.h"
+
+class GeomDataAPI_Point2D;
+
+/*!
+ \class PartSet_FeatureLinePrs
+ * \brief The abstract class to define the specific feature manipulation. It is created for
+ * the feature create operation to move out the feature properties set and use one operation
+ * for any type of features.
+*/
+class PARTSET_EXPORT PartSet_FeatureLinePrs : public PartSet_FeaturePrs
+{
+public:
+ /// Constructor
+ /// \param theSketch the sketch feature
+ PartSet_FeatureLinePrs(FeaturePtr theSketch);
+ /// Destructor
+ virtual ~PartSet_FeatureLinePrs() {};
+
+ /// Sets the point to the feature in an attribute depending on the selection mode
+ /// \param theX the 2D point horizontal coordinate
+ /// \param theY the 2D point vertical coordinate
+ /// \param theMode the selection mode
+ /// \return the new selection mode
+ virtual PartSet_SelectionMode setPoint(double theX, double theY,
+ const PartSet_SelectionMode& theMode);
+
+ /// Returns the feature attribute name for the selection mode
+ /// \param theMode the current operation selection mode. The feature attribute depends on the mode
+ virtual std::string getAttribute(const PartSet_SelectionMode& theMode) const;
+
+ /// Returns the next selection mode after the attribute
+ /// \param theAttribute the feature attribute name
+ /// \return next attribute selection mode
+ virtual PartSet_SelectionMode getNextMode(const std::string& theAttribute) const;
+
+protected:
+ /// Initializes current feature by the given
+ /// \param theSourceFeature the feature, which attributes are used to initialize the current feature
+ virtual void initFeature(FeaturePtr theSourceFeature);
+
+ /// Returns the feature point in the selection mode position.
+ /// \param theMode the current operation selection mode. The feature attribute depends on the mode
+ virtual boost::shared_ptr<GeomDataAPI_Point2D> featurePoint(const PartSet_SelectionMode& theMode);
+};
+
+#endif
--- /dev/null
+// File: PartSet_FeaturePointPrs.h
+// Created: 04 Jun 2014
+// Author: Natalia ERMOLAEVA
+
+#include <PartSet_FeaturePointPrs.h>
+#include <PartSet_Tools.h>
+
+#include <SketchPlugin_Feature.h>
+#include <SketchPlugin_Sketch.h>
+#include <SketchPlugin_ConstraintCoincidence.h>
+#include <SketchPlugin_Line.h>
+#include <SketchPlugin_Constraint.h>
+
+#include <GeomDataAPI_Point2D.h>
+
+#include <ModelAPI_Data.h>
+#include <ModelAPI_Document.h>
+#include <ModelAPI_AttributeRefAttr.h>
+#include <ModelAPI_AttributeRefList.h>
+
+#include <Precision.hxx>
+
+using namespace std;
+
+PartSet_FeaturePointPrs::PartSet_FeaturePointPrs(FeaturePtr theFeature)
+{
+}
+
+PartSet_FeaturePointPrs::~PartSet_FeaturePointPrs()
+{
+}
--- /dev/null
+// File: PartSet_FeaturePointPrs.h
+// Created: 04 Jun 2014
+// Author: Natalia ERMOLAEVA
+
+#ifndef PartSet_FeaturePointPrs_H
+#define PartSet_FeaturePointPrs_H
+
+#include "PartSet.h"
+
+#include "PartSet_Constants.h"
+
+class GeomDataAPI_Point2D;
+
+/*!
+ \class PartSet_FeaturePointPrs
+ * \brief The abstract class to define the specific feature manipulation. It is created for
+ * the feature create operation to move out the feature properties set and use one operation
+ * for any type of features.
+*/
+class PARTSET_EXPORT PartSet_FeaturePointPrs
+{
+public:
+ /// Constructor
+ /// \param theSketch the sketch feature
+ PartSet_FeaturePointPrs(FeaturePtr theSketch);
+ /// Destructor
+ virtual ~PartSet_FeaturePointPrs();
+};
+
+#endif
// Author: Natalia ERMOLAEVA
#include <PartSet_FeaturePrs.h>
+#include <PartSet_Tools.h>
#include <SketchPlugin_Feature.h>
#include <SketchPlugin_Sketch.h>
-#include <SketchPlugin_ConstraintCoincidence.h>
-#include <SketchPlugin_Line.h>
-#include <SketchPlugin_Constraint.h>
#include <GeomDataAPI_Point2D.h>
void PartSet_FeaturePrs::init(FeaturePtr theFeature, FeaturePtr theSourceFeature)
{
myFeature = theFeature;
- if (theSourceFeature)
- {
- // use the last point of the previous feature as the first of the new one
- boost::shared_ptr<ModelAPI_Data> aData = theSourceFeature->data();
- boost::shared_ptr<GeomDataAPI_Point2D> anInitPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
- (aData->attribute(LINE_ATTR_END));
- setLinePoint(theFeature, anInitPoint->x(), anInitPoint->y(), LINE_ATTR_START);
- setLinePoint(theFeature, anInitPoint->x(), anInitPoint->y(), LINE_ATTR_END);
-
- aData = theFeature->data();
- boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
- (aData->attribute(LINE_ATTR_START));
- createConstraint(anInitPoint, aPoint);
+ if (theSourceFeature) {
+ initFeature(theSourceFeature);
}
}
-boost::shared_ptr<ModelAPI_Document> PartSet_FeaturePrs::document() const
-{
- return ModelAPI_PluginManager::get()->rootDocument();
-}
-
FeaturePtr PartSet_FeaturePrs::sketch() const
{
return mySketch;
}
-PartSet_SelectionMode PartSet_FeaturePrs::setPoint(double theX, double theY,
- const PartSet_SelectionMode& theMode)
-{
- PartSet_SelectionMode aMode = theMode;
- switch (theMode)
- {
- case SM_FirstPoint: {
- setLinePoint(feature(), theX, theY, LINE_ATTR_START);
- setLinePoint(feature(), theX, theY, LINE_ATTR_END);
- aMode = SM_SecondPoint;
- }
- break;
- case SM_SecondPoint: {
- setLinePoint(feature(), theX, theY, LINE_ATTR_END);
- aMode = SM_DonePoint;
- }
- break;
- default:
- break;
- }
- return aMode;
-}
-
FeaturePtr PartSet_FeaturePrs::feature() const
{
return myFeature;
}
-void PartSet_FeaturePrs::createConstraint(boost::shared_ptr<GeomDataAPI_Point2D> thePoint1,
- boost::shared_ptr<GeomDataAPI_Point2D> thePoint2)
-{
- boost::shared_ptr<ModelAPI_Document> aDoc = document();
- FeaturePtr aFeature = aDoc->addFeature(SKETCH_CONSTRAINT_COINCIDENCE_KIND);
-
- if (sketch()) {
- boost::shared_ptr<SketchPlugin_Feature> aSketch =
- boost::dynamic_pointer_cast<SketchPlugin_Feature>(sketch());
- aSketch->addSub(aFeature);
- }
-
- boost::shared_ptr<ModelAPI_Data> aData = aFeature->data();
-
- boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef1 =
- boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_A));
- aRef1->setAttr(thePoint1);
-
- boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef2 =
- boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_B));
- aRef2->setAttr(thePoint2);
-
- if (aFeature) // TODO: generate an error if feature was not created
- aFeature->execute();
-}
-
void PartSet_FeaturePrs::setConstraints(double theX, double theY,
const PartSet_SelectionMode& theMode)
{
- std::string aPointArg;
- switch (theMode)
- {
- case SM_FirstPoint:
- aPointArg = LINE_ATTR_START;
- break;
- case SM_SecondPoint:
- aPointArg = LINE_ATTR_END;
- break;
- default:
- break;
- }
+ // find a feature point by the selection mode
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint = featurePoint(theMode);
- FeaturePtr aSkFeature = feature();
-
- boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
- boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
- (aData->attribute(aPointArg));
- aData = sketch()->data();
+ // get all sketch features. If the point with the given coordinates belong to any sketch feature,
+ // the constraint is created between the feature point and the found sketch point
+ boost::shared_ptr<ModelAPI_Data> aData = sketch()->data();
boost::shared_ptr<ModelAPI_AttributeRefList> aRefList =
boost::dynamic_pointer_cast<ModelAPI_AttributeRefList>(aData->attribute(SKETCH_ATTR_FEATURES));
std::list<FeaturePtr > aFeatures = aRefList->list();
- std::list<FeaturePtr >::const_iterator anIt = aFeatures.begin(),
- aLast = aFeatures.end();
- for (; anIt != aLast; anIt++) {
+ std::list<FeaturePtr >::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end();
+ for (; anIt != aLast; anIt++)
+ {
FeaturePtr aFeature = *anIt;
- boost::shared_ptr<GeomDataAPI_Point2D> aFPoint = findLinePoint(aFeature, theX, theY);
+ boost::shared_ptr<GeomDataAPI_Point2D> aFPoint = PartSet_Tools::findPoint(aFeature, theX, theY);
if (aFPoint)
- createConstraint(aFPoint, aPoint);
+ PartSet_Tools::createConstraint(sketch(), aFPoint, aPoint);
}
}
-
-std::string PartSet_FeaturePrs::getAttribute(const PartSet_SelectionMode& theMode) const
-{
- std::string aAttribute;
- switch (theMode)
- {
- case SM_FirstPoint:
- aAttribute = LINE_ATTR_START;
- break;
- case SM_SecondPoint:
- aAttribute = LINE_ATTR_END;
- break;
- default:
- break;
- }
- return aAttribute;
-}
-
-PartSet_SelectionMode PartSet_FeaturePrs::getNextMode(const std::string& theAttribute) const
-{
- PartSet_SelectionMode aMode;
-
- if (theAttribute == LINE_ATTR_START)
- aMode = SM_SecondPoint;
- else if (theAttribute == LINE_ATTR_END)
- aMode = SM_DonePoint;
- return aMode;
-}
-
-void PartSet_FeaturePrs::getLinePoint(FeaturePtr theFeature,
- const std::string& theAttribute,
- double& theX, double& theY)
-{
- if (!theFeature || theFeature->getKind() != SKETCH_LINE_KIND)
- return;
- boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
- boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(theAttribute));
- theX = aPoint->x();
- theY = aPoint->y();
-}
-
-boost::shared_ptr<GeomDataAPI_Point2D> PartSet_FeaturePrs::findLinePoint(
- FeaturePtr theFeature,
- double theX, double theY)
-{
- boost::shared_ptr<GeomDataAPI_Point2D> aPoint2D;
- if (!theFeature || theFeature->getKind() != SKETCH_LINE_KIND)
- return aPoint2D;
- boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
-
- boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_START));
- if (fabs(aPoint->x() - theX) < Precision::Confusion() && fabs(aPoint->y() - theY) < Precision::Confusion() )
- aPoint2D = aPoint;
- else {
- aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_END));
- if (fabs(aPoint->x() - theX) < Precision::Confusion() && fabs(aPoint->y() - theY) < Precision::Confusion() )
- aPoint2D = aPoint;
- }
- return aPoint2D;
-}
-
-void PartSet_FeaturePrs::setLinePoint(FeaturePtr theFeature,
- double theX, double theY,
- const std::string& theAttribute)
-{
- if (!theFeature)
- return;
- boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
- boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(theAttribute));
- aPoint->setValue(theX, theY);
-}
/// Saves the fiature as the presentation internal feature
/// \param theFeature the presentation feature
/// \param theSourceFeature the feature, which attributes are used to initialize the feature
- virtual void init(FeaturePtr theFeature, FeaturePtr theSourceFeature);
+ void init(FeaturePtr theFeature, FeaturePtr theSourceFeature);
/// Returns the operation sketch feature
/// \returns the sketch instance
/// \param theY the 2D point vertical coordinate
/// \param theMode the selection mode
/// \return the new selection mode
- PartSet_SelectionMode setPoint(double theX, double theY, const PartSet_SelectionMode& theMode);
-
- /// Creates constrains of the current
- /// \param theX the horizontal coordnate of the point
- /// \param theY the vertical coordnate of the point
- /// \param theMode the current operation selection mode. The feature attribute depends on the mode
- void setConstraints(double theX, double theY, const PartSet_SelectionMode& theMode);
+ virtual PartSet_SelectionMode setPoint(double theX, double theY,
+ const PartSet_SelectionMode& theMode) = 0;
/// Returns the feature attribute name for the selection mode
/// \param theMode the current operation selection mode. The feature attribute depends on the mode
- std::string getAttribute(const PartSet_SelectionMode& theMode) const;
+ virtual std::string getAttribute(const PartSet_SelectionMode& theMode) const = 0;
/// Returns the next selection mode after the attribute
/// \param theAttribute the feature attribute name
/// \return next attribute selection mode
- PartSet_SelectionMode getNextMode(const std::string& theAttribute) const;
+ virtual PartSet_SelectionMode getNextMode(const std::string& theAttribute) const = 0;
- /// \brief Save the point to the line.
- /// \param theFeature the line feature
- /// \param theX the horizontal coordinate
- /// \param theY the vertical coordinate
- /// \param theAttribute the start or end attribute of the line
- static void setLinePoint(FeaturePtr, double theX, double theY,
- const std::string& theAttribute);
+ /// Creates constrains of the current
+ /// \param theX the horizontal coordnate of the point
+ /// \param theY the vertical coordnate of the point
+ /// \param theMode the current operation selection mode. The feature attribute depends on the mode
+ void setConstraints(double theX, double theY, const PartSet_SelectionMode& theMode);
protected:
- /// Returns pointer to the root document.
- boost::shared_ptr<ModelAPI_Document> document() const;
-
- /// Returns the operation feature
+ /// Returns the operation feature
/// \return the feature
FeaturePtr feature() const;
- /// Creates a constraint on two points
- /// \param thePoint1 the first point
- /// \param thePoint1 the second point
- void createConstraint(boost::shared_ptr<GeomDataAPI_Point2D> thePoint1,
- boost::shared_ptr<GeomDataAPI_Point2D> thePoint2);
-
- /// \brief Get the line point 2d coordinates.
- /// \param theFeature the line feature
- /// \param theAttribute the start or end attribute of the line
- /// \param theX the horizontal coordinate
- /// \param theY the vertical coordinate
- void getLinePoint(FeaturePtr theFeature, const std::string& theAttribute,
- 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
- boost::shared_ptr<GeomDataAPI_Point2D> findLinePoint(FeaturePtr theFeature,
- double theX, double theY);
+ /// Initializes current feature by the given
+ /// \param theSourceFeature the feature, which attributes are used to initialize the current feature
+ virtual void initFeature(FeaturePtr theSourceFeature) = 0;
+
+ /// Returns the feature point in the selection mode position.
+ /// \param theMode the current operation selection mode. The feature attribute depends on the mode
+ virtual boost::shared_ptr<GeomDataAPI_Point2D> featurePoint(const PartSet_SelectionMode& theMode) = 0;
private:
FeaturePtr mySketch; ///< the sketch of the feature
if (aFeature) {
double X0, X1, X2, X3;
double Y0, Y1, Y2, Y3;
- getLinePoint(aFeature, LINE_ATTR_START, X2, Y2);
- getLinePoint(aFeature, LINE_ATTR_END, X3, Y3);
+ PartSet_Tools::getLinePoint(aFeature, LINE_ATTR_START, X2, Y2);
+ PartSet_Tools::getLinePoint(aFeature, LINE_ATTR_END, X3, Y3);
PartSet_Tools::convertTo2D(aPoint, sketch(), theView, X1, Y1);
switch (myPointSelectionMode) {
PartSet_Tools::projectPointOnLine(X2, Y2, X3, Y3, X1, Y1, aX, anY);
break;
case SM_SecondPoint: {
- getLinePoint(feature(), LINE_ATTR_START, X0, Y0);
+ PartSet_Tools::getLinePoint(feature(), LINE_ATTR_START, X0, Y0);
PartSet_Tools::intersectLines(X0, Y0, X1, Y1, X2, Y2, X3, Y3, aX, anY);
}
break;
boost::shared_ptr<ModelAPI_Data> aData = aNewFeature->data();
boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
(aData->attribute(LINE_ATTR_START));
- createConstraint(myInitPoint, aPoint);
+ PartSet_Tools::createConstraint(myInitPoint, aPoint);
}*/
emit featureConstructed(aNewFeature, FM_Activation);
#include <PartSet_Tools.h>
#include <PartSet_OperationSketch.h>
-#include <PartSet_FeaturePrs.h>
+#include <PartSet_FeatureLinePrs.h>
#include <SketchPlugin_Feature.h>
: PartSet_OperationSketchBase(theId, theParent),
myPointSelectionMode(SM_FirstPoint)
{
- myFeaturePrs = new PartSet_FeaturePrs(theFeature);
+ myFeaturePrs = new PartSet_FeatureLinePrs(theFeature);
}
PartSet_OperationCreateFeature::~PartSet_OperationCreateFeature()
myFeaturePrs->setConstraints(aX, anY, myPointSelectionMode);
}
}
- /*else if (aShape.ShapeType() == TopAbs_EDGE) // the line is selected
+ else if (aShape.ShapeType() == TopAbs_EDGE) // the line is selected
{
+ PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
+ isFoundPoint = true;
+ /*
FeaturePtr aFeature = aPrs.feature();
if (aFeature) {
double X0, X1, X2, X3;
double Y0, Y1, Y2, Y3;
- getLinePoint(aFeature, LINE_ATTR_START, X2, Y2);
- getLinePoint(aFeature, LINE_ATTR_END, X3, Y3);
+ PartSet_Tools::getLinePoint(aFeature, LINE_ATTR_START, X2, Y2);
+ PartSet_Tools::getLinePoint(aFeature, LINE_ATTR_END, X3, Y3);
PartSet_Tools::convertTo2D(aPoint, sketch(), theView, X1, Y1);
switch (myPointSelectionMode) {
PartSet_Tools::projectPointOnLine(X2, Y2, X3, Y3, X1, Y1, aX, anY);
break;
case SM_SecondPoint: {
- getLinePoint(feature(), LINE_ATTR_START, X0, Y0);
+ PartSet_Tools::getLinePoint(feature(), LINE_ATTR_START, X0, Y0);
PartSet_Tools::intersectLines(X0, Y0, X1, Y1, X2, Y2, X3, Y3, aX, anY);
}
break;
}
isFoundPoint = true;
}
- }*/
+ */
+ }
}
}
#include <XGUI_ViewerProxy.h>
#include <PartSet_FeaturePrs.h>
#include <PartSet_Presentation.h>
+#include <PartSet_Tools.h>
#include <PartSet_OperationSketchBase.h>
#include <ModelAPI_Feature.h>
boost::dynamic_pointer_cast<SketchPlugin_Feature>(aPreviewOp->sketch());
aSketch->addSub(aFeature);
- PartSet_FeaturePrs::setLinePoint(aFeature, 100, 100, LINE_ATTR_START);
- PartSet_FeaturePrs::setLinePoint(aFeature, 150, 300, LINE_ATTR_END);
+ PartSet_Tools::setFeaturePoint(aFeature, 100, 100, LINE_ATTR_START);
+ PartSet_Tools::setFeaturePoint(aFeature, 150, 300, LINE_ATTR_END);
boost::shared_ptr<GeomAPI_Shape> aPreview = PartSet_OperationSketchBase::preview(aFeature);
/*double aDelta = -200;
for (int i = 0; i < 20; i++) {
aDelta = aDelta - i*2;
- PartSet_FeaturePrs::setLinePoint(aFeature, 100+aDelta, 200+aDelta, LINE_ATTR_START);
- PartSet_FeaturePrs::setLinePoint(aFeature, 300+aDelta, 500+aDelta, LINE_ATTR_END);
+ PartSet_Tools::setFeaturePoint(aFeature, 100+aDelta, 200+aDelta, LINE_ATTR_START);
+ PartSet_Tools::setFeaturePoint(aFeature, 300+aDelta, 500+aDelta, LINE_ATTR_END);
boost::shared_ptr<GeomAPI_Shape> aPreview = PartSet_OperationSketchBase::preview(aFeature);
Handle(AIS_InteractiveObject) anAIS = PartSet_Presentation::createPresentation(
myTestDelta = myTestDelta - 50;
double aDelta = myTestDelta;
- PartSet_FeaturePrs::setLinePoint(aFeature, -100/*aDelta*/, -100/*aDelta*/, LINE_ATTR_START);
- PartSet_FeaturePrs::setLinePoint(aFeature, 200/*aDelta*2*/, 200/*aDelta*2*/, LINE_ATTR_END);
+ PartSet_Tools::setFeaturePoint(aFeature, -100/*aDelta*/, -100/*aDelta*/, LINE_ATTR_START);
+ PartSet_Tools::setFeaturePoint(aFeature, 200/*aDelta*2*/, 200/*aDelta*2*/, LINE_ATTR_END);
boost::shared_ptr<GeomAPI_Shape> aPreview = PartSet_OperationSketchBase::preview(aFeature);
Handle(AIS_InteractiveObject) aPrevAIS;
#include <ModelAPI_Data.h>
#include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_Document.h>
#include <GeomDataAPI_Point.h>
#include <GeomDataAPI_Dir.h>
#include <GeomAPI_Dir.h>
#include <GeomAPI_XYZ.h>
+#include <SketchPlugin_Feature.h>
#include <SketchPlugin_Sketch.h>
#include <SketchPlugin_Line.h>
+#include <SketchPlugin_ConstraintCoincidence.h>
+#include <SketchPlugin_Constraint.h>
#include <XGUI_ViewerPrs.h>
return aDelta;
}
+
+boost::shared_ptr<ModelAPI_Document> PartSet_Tools::document()
+{
+ return ModelAPI_PluginManager::get()->rootDocument();
+}
+
+void PartSet_Tools::setFeaturePoint(FeaturePtr theFeature, double theX, double theY,
+ const std::string& theAttribute)
+{
+ if (!theFeature)
+ return;
+ boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(theAttribute));
+ if (aPoint)
+ aPoint->setValue(theX, theY);
+}
+
+void PartSet_Tools::createConstraint(FeaturePtr theSketch,
+ boost::shared_ptr<GeomDataAPI_Point2D> thePoint1,
+ boost::shared_ptr<GeomDataAPI_Point2D> thePoint2)
+{
+ boost::shared_ptr<ModelAPI_Document> aDoc = document();
+ FeaturePtr aFeature = aDoc->addFeature(SKETCH_CONSTRAINT_COINCIDENCE_KIND);
+
+ if (theSketch) {
+ boost::shared_ptr<SketchPlugin_Feature> aSketch =
+ boost::dynamic_pointer_cast<SketchPlugin_Feature>(theSketch);
+ aSketch->addSub(aFeature);
+ }
+
+ boost::shared_ptr<ModelAPI_Data> aData = aFeature->data();
+
+ boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef1 =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_A));
+ aRef1->setAttr(thePoint1);
+
+ boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef2 =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_B));
+ aRef2->setAttr(thePoint2);
+
+ if (aFeature) // TODO: generate an error if feature was not created
+ aFeature->execute();
+}
+
+void PartSet_Tools::getLinePoint(FeaturePtr theFeature, const std::string& theAttribute,
+ double& theX, double& theY)
+{
+ if (!theFeature || theFeature->getKind() != SKETCH_LINE_KIND)
+ return;
+ boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(theAttribute));
+ theX = aPoint->x();
+ theY = aPoint->y();
+}
+
+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<ModelAPI_Data> aData = theFeature->data();
+ if (theFeature->getKind() == SKETCH_LINE_KIND)
+ {
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_START));
+ if (fabs(aPoint->x() - theX) < Precision::Confusion() && fabs(aPoint->y() - theY) < Precision::Confusion() )
+ aPoint2D = aPoint;
+ else {
+ aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_END));
+ if (fabs(aPoint->x() - theX) < Precision::Confusion() && fabs(aPoint->y() - theY) < Precision::Confusion() )
+ aPoint2D = aPoint;
+ }
+ }
+ return aPoint2D;
+}
class Handle_V3d_View;
class XGUI_ViewerPrs;
+class GeomDataAPI_Point2D;
/*!
\class PartSet_Tools
/// \param theY the Y coordinate
/// \param theSketch the sketch feature
/// \param thePoint the 3D point in the viewer
- static void convertTo3D(const double theX, const double theY,
- FeaturePtr theSketch,
+ static void convertTo3D(const double theX, const double theY, FeaturePtr theSketch,
gp_Pnt& thePoint);
/// Returns the point of intersection of the two lines, the first is (v0, v1), the second is (v2, v3),
/// \param theView a 3D view
/// \param theSketch the sketch feature
/// \param theFeatures the list of selected presentations
- static FeaturePtr nearestFeature(QPoint thePoint, Handle_V3d_View theView,
- FeaturePtr theSketch,
- const std::list<XGUI_ViewerPrs>& theFeatures);
+ static FeaturePtr nearestFeature(QPoint thePoint, Handle_V3d_View theView, FeaturePtr theSketch,
+ const std::list<XGUI_ViewerPrs>& theFeatures);
+
+ /// Returns pointer to the root document.
+ static boost::shared_ptr<ModelAPI_Document> document();
+
+ /// \brief Save the point to the feature. If the attribute is 2D geometry point, it is filled.
+ /// \param theFeature the feature
+ /// \param theX the horizontal coordinate
+ /// \param theY the vertical coordinate
+ /// \param theAttribute the feature attribute
+ static void setFeaturePoint(FeaturePtr, double theX, double theY, const std::string& theAttribute);
+
+ /// Creates a constraint on two points
+ /// \param thePoint1 the first point
+ /// \param thePoint1 the second point
+ static void createConstraint(FeaturePtr theSketch,
+ boost::shared_ptr<GeomDataAPI_Point2D> thePoint1,
+ boost::shared_ptr<GeomDataAPI_Point2D> thePoint2);
+
+ /// \brief Get the line point 2d coordinates.
+ /// \param theFeature the line feature
+ /// \param theAttribute the start or end attribute of the line
+ /// \param theX the horizontal coordinate
+ /// \param theY the vertical coordinate
+ static void getLinePoint(FeaturePtr theFeature, const std::string& theAttribute,
+ 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);
+
private:
/// 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);
+ static double distanceToPoint(FeaturePtr theFeature, double theX, double theY);
};
#endif