SET(PROJECT_HEADERS
PartSet.h
+ PartSet_Constants.h
+ PartSet_FeaturePrs.h
+ PartSet_FeatureLinePrs.h
+ PartSet_FeaturePointPrs.h
PartSet_Listener.h
PartSet_Module.h
PartSet_OperationConstraint.h
+ PartSet_OperationCreateFeature.h
PartSet_OperationEditLine.h
PartSet_OperationSketchBase.h
PartSet_OperationSketch.h
- PartSet_OperationSketchLine.h
PartSet_Presentation.h
PartSet_TestOCC.h
PartSet_Tools.h
)
SET(PROJECT_SOURCES
+ PartSet_FeaturePrs.cpp
+ PartSet_FeatureLinePrs.cpp
+ PartSet_FeaturePointPrs.cpp
PartSet_Listener.cpp
PartSet_Module.cpp
PartSet_OperationConstraint.cpp
+ PartSet_OperationCreateFeature.cpp
PartSet_OperationEditLine.cpp
PartSet_OperationSketchBase.cpp
PartSet_OperationSketch.cpp
- PartSet_OperationSketchLine.cpp
PartSet_Presentation.cpp
PartSet_TestOCC.cpp
PartSet_Tools.cpp
--- /dev/null
+// File: PartSet_Tools.h
+// Created: 04 Jun 2014
+// Author: Natalia ERMOLAEVA
+
+#ifndef PartSet_Constants_H
+#define PartSet_Constants_H
+
+#include <ModelAPI_Feature.h>
+
+/// This file contains various constants used in the PartSet module
+
+/// Types of viewer selection in an operation
+enum PartSet_SelectionMode
+{
+ SM_FirstPoint,
+ SM_SecondPoint,
+ SM_DonePoint
+};
+
+
+#endif
--- /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
--- /dev/null
+// File: PartSet_FeaturePrs.h
+// Created: 04 Jun 2014
+// Author: Natalia ERMOLAEVA
+
+#include <PartSet_FeaturePrs.h>
+#include <PartSet_Tools.h>
+
+#include <SketchPlugin_Feature.h>
+#include <SketchPlugin_Sketch.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_FeaturePrs::PartSet_FeaturePrs(FeaturePtr theFeature)
+: mySketch(theFeature)
+{
+}
+
+PartSet_FeaturePrs::~PartSet_FeaturePrs()
+{
+}
+
+void PartSet_FeaturePrs::init(FeaturePtr theFeature, FeaturePtr theSourceFeature)
+{
+ myFeature = theFeature;
+ if (theSourceFeature) {
+ initFeature(theSourceFeature);
+ }
+}
+
+FeaturePtr PartSet_FeaturePrs::sketch() const
+{
+ return mySketch;
+}
+
+FeaturePtr PartSet_FeaturePrs::feature() const
+{
+ return myFeature;
+}
+
+void PartSet_FeaturePrs::setConstraints(double theX, double theY,
+ const PartSet_SelectionMode& theMode)
+{
+ // find a feature point by the selection mode
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint = featurePoint(theMode);
+
+ // 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++)
+ {
+ FeaturePtr aFeature = *anIt;
+ boost::shared_ptr<GeomDataAPI_Point2D> aFPoint = PartSet_Tools::findPoint(aFeature, theX, theY);
+ if (aFPoint)
+ PartSet_Tools::createConstraint(sketch(), aFPoint, aPoint);
+ }
+}
--- /dev/null
+// File: PartSet_FeaturePrs.h
+// Created: 04 Jun 2014
+// Author: Natalia ERMOLAEVA
+
+#ifndef PartSet_FeaturePrs_H
+#define PartSet_FeaturePrs_H
+
+#include "PartSet.h"
+
+#include "PartSet_Constants.h"
+
+class GeomDataAPI_Point2D;
+
+/*!
+ \class PartSet_FeaturePrs
+ * \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_FeaturePrs
+{
+public:
+ /// Constructor
+ /// \param theSketch the sketch feature
+ PartSet_FeaturePrs(FeaturePtr theSketch);
+ /// Destructor
+ virtual ~PartSet_FeaturePrs();
+
+ /// Initializes some fields of feature accorging to the source feature
+ /// 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
+ void init(FeaturePtr theFeature, FeaturePtr theSourceFeature);
+
+ /// Returns the operation sketch feature
+ /// \returns the sketch instance
+ FeaturePtr sketch() const;
+
+ /// 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) = 0;
+
+ /// 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 = 0;
+
+ /// 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 = 0;
+
+ /// 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 the operation feature
+ /// \return the feature
+ FeaturePtr feature() const;
+
+ /// 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
+ FeaturePtr myFeature; ///< the feature
+};
+
+#endif
#include <PartSet_Module.h>
#include <PartSet_OperationSketch.h>
-#include <PartSet_OperationSketchLine.h>
+#include <PartSet_OperationCreateFeature.h>
#include <PartSet_OperationEditLine.h>
#include <PartSet_OperationConstraint.h>
#include <ModuleBase_Operation.h>
// get operation xml description
std::string aStdCmdId = theCmdId;
if (aStdCmdId == PartSet_OperationEditLine::Type())
- aStdCmdId = PartSet_OperationSketchLine::Type();
+ aStdCmdId = SKETCH_LINE_KIND;
std::string aPluginFileName = featureFile(aStdCmdId);
Config_WidgetReader aWdgReader = Config_WidgetReader(aPluginFileName);
aWdgReader.readAll();
PartSet_OperationSketchBase* aPrevOp = dynamic_cast<PartSet_OperationSketchBase*>(aCurOperation);
if (aPrevOp)
aSketch = aPrevOp->sketch();
- if (theCmdId == PartSet_OperationSketchLine::Type())
- anOperation = new PartSet_OperationSketchLine(theCmdId.c_str(), this, aSketch);
+ if (theCmdId == SKETCH_LINE_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);
else if (theCmdId == PartSet_OperationConstraint::Type())
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);
--- /dev/null
+// File: PartSet_OperationCreateFeature.h
+// Created: 20 Apr 2014
+// Author: Natalia ERMOLAEVA
+
+#include <PartSet_OperationCreateFeature.h>
+
+#include <PartSet_Tools.h>
+#include <PartSet_OperationSketch.h>
+#include <PartSet_FeatureLinePrs.h>
+
+#include <SketchPlugin_Feature.h>
+
+#include <ModuleBase_OperationDescription.h>
+
+#include <XGUI_ViewerPrs.h>
+#include <XGUI_Constants.h>
+
+#include <V3d_View.hxx>
+#include <TopoDS_Vertex.hxx>
+#include <TopoDS.hxx>
+#include <BRep_Tool.hxx>
+
+#ifdef _DEBUG
+#include <QDebug>
+#endif
+
+#include <QMouseEvent>
+
+using namespace std;
+
+PartSet_OperationCreateFeature::PartSet_OperationCreateFeature(const QString& theId,
+ QObject* theParent,
+ FeaturePtr theFeature)
+: PartSet_OperationSketchBase(theId, theParent),
+ myPointSelectionMode(SM_FirstPoint)
+{
+ myFeaturePrs = new PartSet_FeatureLinePrs(theFeature);
+}
+
+PartSet_OperationCreateFeature::~PartSet_OperationCreateFeature()
+{
+ delete myFeaturePrs;
+}
+
+bool PartSet_OperationCreateFeature::canBeCommitted() const
+{
+ return myPointSelectionMode == SM_DonePoint;
+}
+
+bool PartSet_OperationCreateFeature::isGranted(ModuleBase_IOperation* theOperation) const
+{
+ return theOperation->getDescription()->operationId().toStdString() == PartSet_OperationSketch::Type();
+}
+
+std::list<int> PartSet_OperationCreateFeature::getSelectionModes(FeaturePtr theFeature) const
+{
+ std::list<int> aModes;
+ if (theFeature != feature())
+ aModes = PartSet_OperationSketchBase::getSelectionModes(theFeature);
+ return aModes;
+}
+
+void PartSet_OperationCreateFeature::init(FeaturePtr theFeature,
+ const std::list<XGUI_ViewerPrs>& /*theSelected*/,
+ const std::list<XGUI_ViewerPrs>& /*theHighlighted*/)
+{
+ if (!theFeature || theFeature->getKind() != SKETCH_LINE_KIND)
+ return;
+ myInitFeature = theFeature;
+}
+
+FeaturePtr PartSet_OperationCreateFeature::sketch() const
+{
+ return myFeaturePrs->sketch();
+}
+
+void PartSet_OperationCreateFeature::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView,
+ const std::list<XGUI_ViewerPrs>& theSelected,
+ const std::list<XGUI_ViewerPrs>& /*theHighlighted*/)
+{
+ if (myPointSelectionMode == SM_DonePoint)
+ {
+ // if the point creation is finished, the next mouse release should commit the modification
+ // the next release can happens by double click in the viewer
+ commit();
+ restartOperation(feature()->getKind(), feature());
+ return;
+ }
+
+ double aX, anY;
+
+ bool isFoundPoint = false;
+ gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView);
+ if (theSelected.empty()) {
+ PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
+ isFoundPoint = true;
+ }
+ else {
+ XGUI_ViewerPrs aPrs = theSelected.front();
+ const TopoDS_Shape& aShape = aPrs.shape();
+ if (!aShape.IsNull()) // the point is selected
+ {
+ if (aShape.ShapeType() == TopAbs_VERTEX) {
+ const TopoDS_Vertex& aVertex = TopoDS::Vertex(aShape);
+ if (!aVertex.IsNull()) {
+ aPoint = BRep_Tool::Pnt(aVertex);
+ PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
+ isFoundPoint = true;
+
+ myFeaturePrs->setConstraints(aX, anY, myPointSelectionMode);
+ }
+ }
+ 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;
+ 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) {
+ case SM_FirstPoint:
+ PartSet_Tools::projectPointOnLine(X2, Y2, X3, Y3, X1, Y1, aX, anY);
+ break;
+ case SM_SecondPoint: {
+ PartSet_Tools::getLinePoint(feature(), LINE_ATTR_START, X0, Y0);
+ PartSet_Tools::intersectLines(X0, Y0, X1, Y1, X2, Y2, X3, Y3, aX, anY);
+ }
+ break;
+ default:
+ break;
+ }
+ isFoundPoint = true;
+ }
+ */
+ }
+ }
+ }
+
+ switch (myPointSelectionMode)
+ {
+ case SM_FirstPoint:
+ case SM_SecondPoint: {
+ PartSet_SelectionMode aMode = myFeaturePrs->setPoint(aX, anY, myPointSelectionMode);
+ flushUpdated();
+ setPointSelectionMode(aMode);
+ }
+ break;
+ default:
+ break;
+ }
+}
+
+void PartSet_OperationCreateFeature::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
+{
+ switch (myPointSelectionMode)
+ {
+ case SM_FirstPoint:
+ case SM_SecondPoint:
+ {
+ double aX, anY;
+ gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView);
+ PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
+ myFeaturePrs->setPoint(aX, anY, myPointSelectionMode);
+
+ flushUpdated();
+ emit focusActivated(myFeaturePrs->getAttribute(myPointSelectionMode));
+ }
+ break;
+ case SM_DonePoint:
+ {
+ commit();
+ restartOperation(feature()->getKind(), feature());
+ }
+ default:
+ break;
+ }
+}
+
+void PartSet_OperationCreateFeature::keyReleased(std::string theName, QKeyEvent* theEvent)
+{
+ int aKeyType = theEvent->key();
+ // the second point should be activated by any modification in the property panel
+ if (!theName.empty() /*&& aKeyType == Qt::Key_Return*/)
+ {
+ setPointSelectionMode(myFeaturePrs->getNextMode(theName), false);
+ }
+ keyReleased(theEvent->key());
+}
+
+void PartSet_OperationCreateFeature::keyReleased(const int theKey)
+{
+ switch (theKey) {
+ case Qt::Key_Return: {
+ if (myPointSelectionMode == SM_DonePoint)
+ {
+ commit();
+ // it start a new line creation at a free point
+ restartOperation(feature()->getKind(), FeaturePtr()/*feature()*/);
+ }
+ //else
+ // abort();
+ //restartOperation(feature()->getKind(), FeaturePtr());
+ }
+ break;
+ case Qt::Key_Escape: {
+ if (myPointSelectionMode == SM_DonePoint)
+ {
+ commit();
+ }
+ else
+ {
+ abort();
+ }
+ }
+ default:
+ break;
+ }
+}
+
+void PartSet_OperationCreateFeature::startOperation()
+{
+ PartSet_OperationSketchBase::startOperation();
+ setPointSelectionMode(!myInitFeature ? SM_FirstPoint : SM_SecondPoint);
+
+ emit multiSelectionEnabled(false);
+}
+
+void PartSet_OperationCreateFeature::abortOperation()
+{
+ emit featureConstructed(feature(), FM_Hide);
+ PartSet_OperationSketchBase::abortOperation();
+}
+
+void PartSet_OperationCreateFeature::stopOperation()
+{
+ PartSet_OperationSketchBase::stopOperation();
+ emit multiSelectionEnabled(true);
+}
+
+void PartSet_OperationCreateFeature::afterCommitOperation()
+{
+ PartSet_OperationSketchBase::afterCommitOperation();
+ emit featureConstructed(feature(), FM_Deactivation);
+}
+
+FeaturePtr PartSet_OperationCreateFeature::createFeature(const bool theFlushMessage)
+{
+ FeaturePtr aNewFeature = ModuleBase_Operation::createFeature(false);
+ if (sketch()) {
+ boost::shared_ptr<SketchPlugin_Feature> aFeature =
+ boost::dynamic_pointer_cast<SketchPlugin_Feature>(sketch());
+
+ aFeature->addSub(aNewFeature);
+ }
+ myFeaturePrs->init(aNewFeature, myInitFeature);
+
+ emit featureConstructed(aNewFeature, FM_Activation);
+ if (theFlushMessage)
+ flushCreated();
+ return aNewFeature;
+}
+
+void PartSet_OperationCreateFeature::setPointSelectionMode(const PartSet_SelectionMode& theMode,
+ const bool isToEmitSignal)
+{
+ myPointSelectionMode = theMode;
+ if (isToEmitSignal) {
+ std::string aName = myFeaturePrs->getAttribute(theMode);
+ if (aName.empty() && theMode == SM_DonePoint) {
+ aName = XGUI::PROP_PANEL_OK;
+ }
+ emit focusActivated(aName);
+ }
+}
--- /dev/null
+// File: PartSet_OperationCreateFeature.h
+// Created: 20 Apr 2014
+// Author: Natalia ERMOLAEVA
+
+#ifndef PartSet_OperationCreateFeature_H
+#define PartSet_OperationCreateFeature_H
+
+#include "PartSet.h"
+
+#include <PartSet_OperationSketchBase.h>
+#include <PartSet_Constants.h>
+
+#include <SketchPlugin_Line.h>
+
+#include <QObject>
+
+class PartSet_FeaturePrs;
+class GeomDataAPI_Point2D;
+class QMouseEvent;
+class QKeyEvent;
+
+/*!
+ \class PartSet_OperationCreateFeature
+ * \brief The operation for the sketch feature creation
+*/
+class PARTSET_EXPORT PartSet_OperationCreateFeature : public PartSet_OperationSketchBase
+{
+ Q_OBJECT
+
+public:
+
+public:
+ /// Constructor
+ /// \param theId the feature identifier
+ /// \param theParent the operation parent
+ /// \param theSketch the parent feature
+ PartSet_OperationCreateFeature(const QString& theId, QObject* theParent,
+ FeaturePtr theSketch);
+ /// Destructor
+ virtual ~PartSet_OperationCreateFeature();
+
+ /// Verifies whether this operator can be commited.
+ /// \return Returns TRUE if current operation can be committed, e.g. all parameters are filled
+ virtual bool canBeCommitted() const;
+
+ /// Returns that this operator can be started above already running one.
+ /// The runned operation should be the sketch feature modified operation
+ /// \param theOperation the previous running operation
+ virtual bool isGranted(ModuleBase_IOperation* theOperation) const;
+
+ /// Returns the operation local selection mode
+ /// \param theFeature the feature object to get the selection mode
+ /// \return the selection mode
+ virtual std::list<int> getSelectionModes(FeaturePtr theFeature) const;
+
+ /// Initializes some fields accorging to the feature
+ /// \param theSelected the list of selected presentations
+ /// \param theHighlighted the list of highlighted presentations
+ virtual void init(FeaturePtr theFeature,
+ const std::list<XGUI_ViewerPrs>& theSelected,
+ const std::list<XGUI_ViewerPrs>& theHighlighted);
+
+ /// Returns the operation sketch feature
+ /// \returns the sketch instance
+ virtual FeaturePtr sketch() const;
+
+ /// Gives the current selected objects to be processed by the operation
+ /// \param theEvent the mouse event
+ /// \param theView a viewer to have the viewer the eye position
+ /// \param theSelected the list of selected presentations
+ /// \param theHighlighted the list of highlighted presentations
+ virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
+ const std::list<XGUI_ViewerPrs>& theSelected,
+ const std::list<XGUI_ViewerPrs>& theHighlighted);
+ /// Gives the current mouse point in the viewer
+ /// \param thePoint a point clicked in the viewer
+ /// \param theEvent the mouse event
+ virtual void mouseMoved(QMouseEvent* theEvent, Handle_V3d_View theView);
+ /// Processes the key pressed in the view
+ /// \param theKey a key value
+ virtual void keyReleased(const int theKey);
+
+ virtual void keyReleased(std::string theName, QKeyEvent* theEvent);
+
+protected:
+ /// \brief Virtual method called when operation is started
+ /// Virtual method called when operation started (see start() method for more description)
+ /// After the parent operation body perform, set sketch feature to the created line feature
+ virtual void startOperation();
+
+ /// Virtual method called when operation aborted (see abort() method for more description)
+ /// Before the feature is aborted, it should be hidden from the viewer
+ virtual void abortOperation();
+
+ /// Virtual method called when operation stopped - committed or aborted.
+ /// Restore the multi selection state
+ virtual void stopOperation();
+
+ /// Virtual method called after operation committed (see commit() method for more description)
+ virtual void afterCommitOperation();
+
+ /// Creates an operation new feature
+ /// In addition to the default realization it appends the created line feature to
+ /// the sketch feature
+ /// \param theFlushMessage the flag whether the create message should be flushed
+ /// \returns the created feature
+ virtual FeaturePtr createFeature(const bool theFlushMessage = true);
+
+protected:
+ ///< Set the point selection mode. Emit signal about focus change if necessary.
+ /// \param theMode a new selection mode
+ /// \param isToEmitSignal the neccessity to emit signal
+ void setPointSelectionMode(const PartSet_SelectionMode& theMode,
+ const bool isToEmitSignal = true);
+
+private:
+ PartSet_FeaturePrs* myFeaturePrs; ///< the feature presentation
+ FeaturePtr myInitFeature; ///< the initial feature
+ PartSet_SelectionMode myPointSelectionMode; ///< point selection mode
+};
+
+#endif
+++ /dev/null
-// File: PartSet_OperationSketchLine.h
-// Created: 20 Apr 2014
-// Author: Natalia ERMOLAEVA
-
-#include <PartSet_OperationSketchLine.h>
-
-#include <PartSet_Tools.h>
-#include <PartSet_OperationSketch.h>
-
-#include <SketchPlugin_Feature.h>
-#include <SketchPlugin_Sketch.h>
-#include <SketchPlugin_ConstraintCoincidence.h>
-
-#include <GeomDataAPI_Point2D.h>
-
-#include <ModuleBase_OperationDescription.h>
-
-#include <ModelAPI_Data.h>
-#include <ModelAPI_Document.h>
-#include <ModelAPI_AttributeRefAttr.h>
-#include <ModelAPI_AttributeRefList.h>
-
-#include <SketchPlugin_Constraint.h>
-
-#include <Geom_Line.hxx>
-#include <gp_Lin.hxx>
-
-#include <XGUI_ViewerPrs.h>
-#include <XGUI_Constants.h>
-
-#include <SketchPlugin_Line.h>
-
-#include <V3d_View.hxx>
-#include <TopoDS_Vertex.hxx>
-#include <TopoDS.hxx>
-#include <BRep_Tool.hxx>
-
-#ifdef _DEBUG
-#include <QDebug>
-#endif
-
-#include <QMouseEvent>
-
-using namespace std;
-
-PartSet_OperationSketchLine::PartSet_OperationSketchLine(const QString& theId,
- QObject* theParent,
- FeaturePtr theFeature)
-: PartSet_OperationSketchBase(theId, theParent), mySketch(theFeature),
- myPointSelectionMode(SM_FirstPoint)
-{
-}
-
-PartSet_OperationSketchLine::~PartSet_OperationSketchLine()
-{
-}
-
-bool PartSet_OperationSketchLine::canBeCommitted() const
-{
- return myPointSelectionMode == SM_DonePoint;
-}
-
-bool PartSet_OperationSketchLine::isGranted(ModuleBase_IOperation* theOperation) const
-{
- return theOperation->getDescription()->operationId().toStdString() == PartSet_OperationSketch::Type();
-}
-
-std::list<int> PartSet_OperationSketchLine::getSelectionModes(FeaturePtr theFeature) const
-{
- std::list<int> aModes;
- if (theFeature != feature())
- aModes = PartSet_OperationSketchBase::getSelectionModes(theFeature);
- return aModes;
-}
-
-void PartSet_OperationSketchLine::init(FeaturePtr theFeature,
- const std::list<XGUI_ViewerPrs>& /*theSelected*/,
- const std::list<XGUI_ViewerPrs>& /*theHighlighted*/)
-{
- if (!theFeature || theFeature->getKind() != SKETCH_LINE_KIND)
- return;
- // use the last point of the previous feature as the first of the new one
- boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
- myInitPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_END));
-}
-
-FeaturePtr PartSet_OperationSketchLine::sketch() const
-{
- return mySketch;
-}
-
-void PartSet_OperationSketchLine::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView,
- const std::list<XGUI_ViewerPrs>& theSelected,
- const std::list<XGUI_ViewerPrs>& /*theHighlighted*/)
-{
- if (myPointSelectionMode == SM_DonePoint)
- {
- // if the point creation is finished, the next mouse release should commit the modification
- // the next release can happens by double click in the viewer
- commit();
- restartOperation(PartSet_OperationSketchLine::Type(), feature());
- return;
- }
-
- double aX, anY;
-
- bool isFoundPoint = false;
- gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView);
- if (theSelected.empty()) {
- PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
- isFoundPoint = true;
- }
- else {
- XGUI_ViewerPrs aPrs = theSelected.front();
- const TopoDS_Shape& aShape = aPrs.shape();
- if (!aShape.IsNull()) // the point is selected
- {
- if (aShape.ShapeType() == TopAbs_VERTEX) {
- const TopoDS_Vertex& aVertex = TopoDS::Vertex(aShape);
- if (!aVertex.IsNull()) {
- aPoint = BRep_Tool::Pnt(aVertex);
- PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
- isFoundPoint = true;
-
- setConstraints(aX, anY);
- }
- }
- else if (aShape.ShapeType() == TopAbs_EDGE) // the line is selected
- {
- 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::convertTo2D(aPoint, sketch(), theView, X1, Y1);
-
- switch (myPointSelectionMode) {
- case SM_FirstPoint:
- PartSet_Tools::projectPointOnLine(X2, Y2, X3, Y3, X1, Y1, aX, anY);
- break;
- case SM_SecondPoint: {
- getLinePoint(feature(), LINE_ATTR_START, X0, Y0);
- PartSet_Tools::intersectLines(X0, Y0, X1, Y1, X2, Y2, X3, Y3, aX, anY);
- }
- break;
- default:
- break;
- }
- isFoundPoint = true;
- }
- }
- }
- }
-
- switch (myPointSelectionMode)
- {
- case SM_FirstPoint: {
- setLinePoint(feature(), aX, anY, LINE_ATTR_START);
- setLinePoint(feature(), aX, anY, LINE_ATTR_END);
- flushUpdated();
-
- setPointSelectionMode(SM_SecondPoint);
- }
- break;
- case SM_SecondPoint: {
- setLinePoint(feature(), aX, anY, LINE_ATTR_END);
- flushUpdated();
-
- setPointSelectionMode(SM_DonePoint);
- }
- break;
- default:
- break;
- }
-}
-
-void PartSet_OperationSketchLine::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
-{
- switch (myPointSelectionMode)
- {
- case SM_FirstPoint: {
- double aX, anY;
- gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView);
- PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
- setLinePoint(feature(), aX, anY, LINE_ATTR_START);
- setLinePoint(feature(), aX, anY, LINE_ATTR_END);
- flushUpdated();
- emit focusActivated(LINE_ATTR_START);
- }
- break;
- case SM_SecondPoint:
- {
- gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView);
- setLinePoint(aPoint, theView, LINE_ATTR_END);
- flushUpdated();
- emit focusActivated(LINE_ATTR_END);
- }
- break;
- case SM_DonePoint:
- {
- commit();
- restartOperation(PartSet_OperationSketchLine::Type(), feature());
- }
- default:
- break;
- }
-}
-
-void PartSet_OperationSketchLine::keyReleased(std::string theName, QKeyEvent* theEvent)
-{
- int aKeyType = theEvent->key();
- // the second point should be activated by any modification in the property panel
- if (!theName.empty() /*&& aKeyType == Qt::Key_Return*/) {
- if (theName == LINE_ATTR_START) {
- setPointSelectionMode(SM_SecondPoint, false);
- }
- else if (theName == LINE_ATTR_END) {
- setPointSelectionMode(SM_DonePoint, false);
- }
- }
- keyReleased(theEvent->key());
-}
-
-void PartSet_OperationSketchLine::keyReleased(const int theKey)
-{
- switch (theKey) {
- case Qt::Key_Return: {
- if (myPointSelectionMode == SM_DonePoint)
- {
- commit();
- restartOperation(PartSet_OperationSketchLine::Type(), feature());
- }
- //else
- // abort();
- //emit launchOperation(PartSet_OperationSketchLine::Type(), FeaturePtr());
- }
- break;
- case Qt::Key_Escape: {
- if (myPointSelectionMode == SM_DonePoint)
- {
- commit();
- }
- else
- abort();
- }
- default:
- break;
- }
-}
-
-void PartSet_OperationSketchLine::startOperation()
-{
- PartSet_OperationSketchBase::startOperation();
- setPointSelectionMode(!myInitPoint ? SM_FirstPoint : SM_SecondPoint);
-
- emit multiSelectionEnabled(false);
-}
-
-void PartSet_OperationSketchLine::abortOperation()
-{
- emit featureConstructed(feature(), FM_Hide);
- PartSet_OperationSketchBase::abortOperation();
-}
-
-void PartSet_OperationSketchLine::stopOperation()
-{
- PartSet_OperationSketchBase::stopOperation();
- emit multiSelectionEnabled(true);
-}
-
-void PartSet_OperationSketchLine::afterCommitOperation()
-{
- PartSet_OperationSketchBase::afterCommitOperation();
- emit featureConstructed(feature(), FM_Deactivation);
-}
-
-FeaturePtr PartSet_OperationSketchLine::createFeature(const bool theFlushMessage)
-{
- FeaturePtr aNewFeature = ModuleBase_Operation::createFeature(false);
- if (sketch()) {
- boost::shared_ptr<SketchPlugin_Feature> aFeature =
- boost::dynamic_pointer_cast<SketchPlugin_Feature>(sketch());
-
- aFeature->addSub(aNewFeature);
- }
- if (myInitPoint) {
- setLinePoint(aNewFeature, myInitPoint->x(), myInitPoint->y(), LINE_ATTR_START);
- setLinePoint(aNewFeature, myInitPoint->x(), myInitPoint->y(), LINE_ATTR_END);
-
- 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);
- }
-
- emit featureConstructed(aNewFeature, FM_Activation);
- if (theFlushMessage)
- flushCreated();
- return aNewFeature;
-}
-
-void PartSet_OperationSketchLine::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_OperationSketchLine::setConstraints(double theX, double theY)
-{
- std::string aPointArg;
- switch (myPointSelectionMode)
- {
- case SM_FirstPoint:
- aPointArg = LINE_ATTR_START;
- break;
- case SM_SecondPoint:
- aPointArg = LINE_ATTR_END;
- break;
- default:
- break;
- }
-
- 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();
- 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++) {
- FeaturePtr aFeature = *anIt;
- boost::shared_ptr<GeomDataAPI_Point2D> aFPoint = findLinePoint(aFeature, theX, theY);
- if (aFPoint)
- createConstraint(aFPoint, aPoint);
- }
-}
-
-void PartSet_OperationSketchLine::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_OperationSketchLine::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_OperationSketchLine::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);
-}
-
-void PartSet_OperationSketchLine::setLinePoint(const gp_Pnt& thePoint,
- Handle(V3d_View) theView,
- const std::string& theAttribute)
-{
- double aX, anY;
- PartSet_Tools::convertTo2D(thePoint, sketch(), theView, aX, anY);
- boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
- boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(theAttribute));
- aPoint->setValue(aX, anY);
-}
-
-void PartSet_OperationSketchLine::setPointSelectionMode(const PointSelectionMode& theMode,
- const bool isToEmitSignal)
-{
- myPointSelectionMode = theMode;
- if (isToEmitSignal) {
- std::string aName;
- switch (theMode) {
- case SM_FirstPoint:
- aName = LINE_ATTR_START;
- break;
- case SM_SecondPoint:
- aName = LINE_ATTR_END;
- break;
- case SM_DonePoint:
- aName = XGUI::PROP_PANEL_OK;
- break;
- default:
- break;
- }
- emit focusActivated(aName);
- }
-}
+++ /dev/null
-// File: PartSet_OperationSketchLine.h
-// Created: 20 Apr 2014
-// Author: Natalia ERMOLAEVA
-
-#ifndef PartSet_OperationSketchLine_H
-#define PartSet_OperationSketchLine_H
-
-#include "PartSet.h"
-
-#include <PartSet_OperationSketchBase.h>
-
-#include <SketchPlugin_Line.h>
-
-#include <QObject>
-
-class GeomDataAPI_Point2D;
-class QMouseEvent;
-class QKeyEvent;
-
-/*!
- \class PartSet_OperationSketchLine
- * \brief The operation for the sketch feature creation
-*/
-class PARTSET_EXPORT PartSet_OperationSketchLine : public PartSet_OperationSketchBase
-{
- Q_OBJECT
-
-public:
- /// Returns the operation type key
- static std::string Type() { return SKETCH_LINE_KIND; }
-
-public:
- /// Constructor
- /// \param theId the feature identifier
- /// \param theParent the operation parent
- /// \param theFeature the parent feature
- PartSet_OperationSketchLine(const QString& theId, QObject* theParent,
- FeaturePtr theSketchFeature);
- /// Destructor
- virtual ~PartSet_OperationSketchLine();
-
- /// Verifies whether this operator can be commited.
- /// \return Returns TRUE if current operation can be committed, e.g. all parameters are filled
- virtual bool canBeCommitted() const;
-
- /// Returns that this operator can be started above already running one.
- /// The runned operation should be the sketch feature modified operation
- /// \param theOperation the previous running operation
- virtual bool isGranted(ModuleBase_IOperation* theOperation) const;
-
- /// Returns the operation local selection mode
- /// \param theFeature the feature object to get the selection mode
- /// \return the selection mode
- virtual std::list<int> getSelectionModes(FeaturePtr theFeature) const;
-
- /// Initializes some fields accorging to the feature
- /// \param theSelected the list of selected presentations
- /// \param theHighlighted the list of highlighted presentations
- virtual void init(FeaturePtr theFeature,
- const std::list<XGUI_ViewerPrs>& theSelected,
- const std::list<XGUI_ViewerPrs>& theHighlighted);
-
- /// Returns the operation sketch feature
- /// \returns the sketch instance
- virtual FeaturePtr sketch() const;
-
- /// Gives the current selected objects to be processed by the operation
- /// \param theEvent the mouse event
- /// \param theView a viewer to have the viewer the eye position
- /// \param theSelected the list of selected presentations
- /// \param theHighlighted the list of highlighted presentations
- virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
- const std::list<XGUI_ViewerPrs>& theSelected,
- const std::list<XGUI_ViewerPrs>& theHighlighted);
- /// Gives the current mouse point in the viewer
- /// \param thePoint a point clicked in the viewer
- /// \param theEvent the mouse event
- virtual void mouseMoved(QMouseEvent* theEvent, Handle_V3d_View theView);
- /// Processes the key pressed in the view
- /// \param theKey a key value
- virtual void keyReleased(const int theKey);
-
- virtual void keyReleased(std::string theName, QKeyEvent* theEvent);
-
- /// \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);
-
-protected:
- /// \brief Virtual method called when operation is started
- /// Virtual method called when operation started (see start() method for more description)
- /// After the parent operation body perform, set sketch feature to the created line feature
- virtual void startOperation();
-
- /// Virtual method called when operation aborted (see abort() method for more description)
- /// Before the feature is aborted, it should be hidden from the viewer
- virtual void abortOperation();
-
- /// Virtual method called when operation stopped - committed or aborted.
- /// Restore the multi selection state
- virtual void stopOperation();
-
- /// Virtual method called after operation committed (see commit() method for more description)
- virtual void afterCommitOperation();
-
- /// Creates an operation new feature
- /// In addition to the default realization it appends the created line feature to
- /// the sketch feature
- /// \param theFlushMessage the flag whether the create message should be flushed
- /// \returns the created feature
- virtual FeaturePtr createFeature(const bool theFlushMessage = true);
-
- /// 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);
-
- /// Creates constrains of the current
- /// \param theX the horizontal coordnate of the point
- /// \param theY the vertical coordnate of the point
- void setConstraints(double theX, double theY);
-
-protected:
- /// \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);
-
- /// \brief Save the point to the line.
- /// \param thePoint the 3D point in the viewer
- /// \param theAttribute the start or end attribute of the line
- void setLinePoint(const gp_Pnt& thePoint, Handle(V3d_View) theView, const std::string& theAttribute);
-
-protected:
- ///< Structure to lists the possible types of point selection modes
- enum PointSelectionMode {SM_FirstPoint, SM_SecondPoint, SM_DonePoint};
-
- ///< Set the point selection mode. Emit signal about focus change if necessary.
- /// \param theMode a new selection mode
- /// \param isToEmitSignal the neccessity to emit signal
- void setPointSelectionMode(const PointSelectionMode& theMode, const bool isToEmitSignal = true);
-
-private:
- FeaturePtr mySketch; ///< the sketch feature
- boost::shared_ptr<GeomDataAPI_Point2D> myInitPoint; ///< the first line point
- PointSelectionMode myPointSelectionMode; ///< point selection mode
-};
-
-#endif
#include <XGUI_Displayer.h>
#include <XGUI_ViewerPrs.h>
#include <XGUI_ViewerProxy.h>
-#include <PartSet_OperationSketchLine.h>
+#include <PartSet_FeaturePrs.h>
#include <PartSet_Presentation.h>
+#include <PartSet_Tools.h>
+#include <PartSet_OperationSketchBase.h>
#include <ModelAPI_Feature.h>
if (aPreviewOp) {
// create a line
boost::shared_ptr<ModelAPI_Document> aDoc = ModelAPI_PluginManager::get()->rootDocument();
- FeaturePtr aFeature = aDoc->addFeature(
- PartSet_OperationSketchLine::Type().c_str());
+ FeaturePtr aFeature = aDoc->addFeature(SKETCH_LINE_KIND);
if (aFeature) // TODO: generate an error if feature was not created
aFeature->execute();
boost::dynamic_pointer_cast<SketchPlugin_Feature>(aPreviewOp->sketch());
aSketch->addSub(aFeature);
- PartSet_OperationSketchLine::setLinePoint(aFeature, 100, 100, LINE_ATTR_START);
- PartSet_OperationSketchLine::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_OperationSketchLine::preview(aFeature);
+ boost::shared_ptr<GeomAPI_Shape> aPreview = PartSet_OperationSketchBase::preview(aFeature);
XGUI_Displayer* aDisplayer = theWorkshop->displayer();
/*double aDelta = -200;
for (int i = 0; i < 20; i++) {
aDelta = aDelta - i*2;
- PartSet_OperationSketchLine::setLinePoint(aFeature, 100+aDelta, 200+aDelta, LINE_ATTR_START);
- PartSet_OperationSketchLine::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_OperationSketchLine::preview(aFeature);
+ boost::shared_ptr<GeomAPI_Shape> aPreview = PartSet_OperationSketchBase::preview(aFeature);
Handle(AIS_InteractiveObject) anAIS = PartSet_Presentation::createPresentation(
aFeature, aSketch,
aPreview ? aPreview->impl<TopoDS_Shape>() : TopoDS_Shape(), NULL);
myTestDelta = myTestDelta - 50;
double aDelta = myTestDelta;
- PartSet_OperationSketchLine::setLinePoint(aFeature, -100/*aDelta*/, -100/*aDelta*/, LINE_ATTR_START);
- PartSet_OperationSketchLine::setLinePoint(aFeature, 200/*aDelta*2*/, 200/*aDelta*2*/, LINE_ATTR_END);
- boost::shared_ptr<GeomAPI_Shape> aPreview = PartSet_OperationSketchLine::preview(aFeature);
+ 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;
FeaturePtr aSketch;//NULL
#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