Point feature creation is finished. Constraint for the point is available between two points or a point and a line point.
-// File: PartSet_FeaturePointPrs.h
+// File: PartSet_FeaturePrs.h
// Created: 04 Jun 2014
// Author: Natalia ERMOLAEVA
#include <SketchPlugin_Feature.h>
#include <SketchPlugin_Sketch.h>
-#include <SketchPlugin_ConstraintCoincidence.h>
-#include <SketchPlugin_Line.h>
-#include <SketchPlugin_Constraint.h>
+#include <SketchPlugin_Point.h>
#include <GeomDataAPI_Point2D.h>
using namespace std;
-PartSet_FeaturePointPrs::PartSet_FeaturePointPrs(FeaturePtr theFeature)
+PartSet_FeaturePointPrs::PartSet_FeaturePointPrs(FeaturePtr theSketch)
+: PartSet_FeaturePrs(theSketch)
{
}
-PartSet_FeaturePointPrs::~PartSet_FeaturePointPrs()
+void PartSet_FeaturePointPrs::initFeature(FeaturePtr theFeature)
{
}
+
+PartSet_SelectionMode PartSet_FeaturePointPrs::setPoint(double theX, double theY,
+ const PartSet_SelectionMode& theMode)
+{
+ PartSet_SelectionMode aMode = theMode;
+ switch (theMode)
+ {
+ case SM_FirstPoint: {
+ PartSet_Tools::setFeaturePoint(feature(), theX, theY, POINT_ATTR_COORD);
+ aMode = SM_DonePoint;
+ }
+ break;
+ default:
+ break;
+ }
+ return aMode;
+}
+
+std::string PartSet_FeaturePointPrs::getAttribute(const PartSet_SelectionMode& theMode) const
+{
+ std::string aAttribute;
+ switch (theMode)
+ {
+ case SM_FirstPoint:
+ aAttribute = POINT_ATTR_COORD;
+ break;
+ default:
+ break;
+ }
+ return aAttribute;
+}
+
+PartSet_SelectionMode PartSet_FeaturePointPrs::getNextMode(const std::string& theAttribute) const
+{
+ PartSet_SelectionMode aMode;
+
+ if (theAttribute == POINT_ATTR_COORD)
+ aMode = SM_DonePoint;
+ return aMode;
+}
+
+boost::shared_ptr<GeomDataAPI_Point2D> PartSet_FeaturePointPrs::featurePoint
+ (const PartSet_SelectionMode& theMode)
+{
+ std::string aPointArg;
+ switch (theMode)
+ {
+ case SM_FirstPoint:
+ aPointArg = POINT_ATTR_COORD;
+ 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;
+}
#include "PartSet.h"
+#include "PartSet_FeaturePrs.h"
#include "PartSet_Constants.h"
class GeomDataAPI_Point2D;
* 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
+class PARTSET_EXPORT PartSet_FeaturePointPrs : public PartSet_FeaturePrs
{
public:
/// Constructor
/// \param theSketch the sketch feature
PartSet_FeaturePointPrs(FeaturePtr theSketch);
/// Destructor
- virtual ~PartSet_FeaturePointPrs();
+ virtual ~PartSet_FeaturePointPrs() {};
+
+ /// 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
#include <XGUI_PropertyPanel.h>
#include <XGUI_Tools.h>
+#include <SketchPlugin_Line.h>
+#include <SketchPlugin_Point.h>
+
#include <Config_PointerMessage.h>
#include <Config_ModuleReader.h>
#include <Config_WidgetReader.h>
PartSet_OperationSketchBase* aPrevOp = dynamic_cast<PartSet_OperationSketchBase*>(aCurOperation);
if (aPrevOp)
aSketch = aPrevOp->sketch();
- if (theCmdId == SKETCH_LINE_KIND)
+ if (theCmdId == SKETCH_LINE_KIND || theCmdId == SKETCH_POINT_KIND)
anOperation = new PartSet_OperationCreateFeature(theCmdId.c_str(), this, aSketch);
else if (theCmdId == PartSet_OperationEditLine::Type())
anOperation = new PartSet_OperationEditLine(theCmdId.c_str(), this, aSketch);
#include <PartSet_Tools.h>
#include <PartSet_OperationSketch.h>
#include <PartSet_FeatureLinePrs.h>
+#include <PartSet_FeaturePointPrs.h>
#include <SketchPlugin_Feature.h>
+#include <SketchPlugin_Line.h>
#include <ModuleBase_OperationDescription.h>
using namespace std;
PartSet_OperationCreateFeature::PartSet_OperationCreateFeature(const QString& theId,
- QObject* theParent,
- FeaturePtr theFeature)
+ QObject* theParent,
+ FeaturePtr theFeature)
: PartSet_OperationSketchBase(theId, theParent),
myPointSelectionMode(SM_FirstPoint)
{
- myFeaturePrs = new PartSet_FeatureLinePrs(theFeature);
+ if (theId.toStdString() == SKETCH_LINE_KIND) {
+ myFeaturePrs = new PartSet_FeatureLinePrs(theFeature);
+ }
+ else {
+ myFeaturePrs = new PartSet_FeaturePointPrs(theFeature);
+ }
}
PartSet_OperationCreateFeature::~PartSet_OperationCreateFeature()
#include <PartSet_OperationSketchBase.h>
#include <PartSet_Constants.h>
-#include <SketchPlugin_Line.h>
-
#include <QObject>
class PartSet_FeaturePrs;
#include <SketchPlugin_Feature.h>
#include <SketchPlugin_Sketch.h>
+#include <SketchPlugin_Point.h>
#include <SketchPlugin_Line.h>
#include <SketchPlugin_ConstraintCoincidence.h>
#include <SketchPlugin_Constraint.h>
aPoint2D = aPoint;
}
}
+ else if (theFeature->getKind() == SKETCH_POINT_KIND)
+ {
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(POINT_ATTR_COORD));
+ if (fabs(aPoint->x() - theX) < Precision::Confusion() && fabs(aPoint->y() - theY) < Precision::Confusion() )
+ aPoint2D = aPoint;
+ }
return aPoint2D;
}
#include "SketchPlugin_Sketch.h"
#include <ModelAPI_Data.h>
#include <GeomDataAPI_Point2D.h>
+#include <GeomAlgoAPI_PointBuilder.h>
using namespace std;
boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(POINT_ATTR_COORD));
boost::shared_ptr<GeomAPI_Pnt> aPoint3D(aSketch->to3D(aPoint->x(), aPoint->y()));
// make a visible point
- //boost::shared_ptr<GeomAPI_Shape> anEdge = GeomAlgoAPI_EdgeBuilder::line(aStart, anEnd);
- //setPreview(anEdge);
+ boost::shared_ptr<GeomAPI_Shape> aPointShape = GeomAlgoAPI_PointBuilder::point(aPoint3D);
+ setPreview(aPointShape);
return getPreview();
}
<plugin>
<workbench id="Sketch">
<group id="Basic">
- <feature id="Sketch" nested="SketchLine SketchConstraintLength" title="Sketch" tooltip="Create a new sketch or edit an existing sketch" icon=":icons/sketch.png">
+ <feature id="Sketch" nested="SketchLine SketchPoint SketchConstraintLength" title="Sketch" tooltip="Create a new sketch or edit an existing sketch" icon=":icons/sketch.png">
<label title="Select a plane on which to create a sketch" tooltip="Select a plane on which to create a sketch"/>
<!--icon=":pictures/x_point.png"-->
</feature>
- <feature id="SketchPoint" title="Point" tooltip="Create a new point" icon=":icons/point.png" internal="1"/>
+ <feature id="SketchPoint" title="Point" tooltip="Create a new point" icon=":icons/point.png">
+ <point_selector id="PointCoordindates" title="Point" tooltip="Point"/>
+ </feature>
<feature id="SketchLine" title="Line" tooltip="Create a new line" icon=":icons/line.png">
<point_selector id="StartPoint" title="Start point" tooltip="Start point of the line"/>
<point_selector id="EndPoint" title="End point" tooltip="End point of the line"/>