1. Remove operation constraint class.
2. Edit constraint lenght. To debug
PartSet_FeaturePointPrs.h
PartSet_Listener.h
PartSet_Module.h
- PartSet_OperationConstraint.h
PartSet_OperationCreateConstraint.h
PartSet_OperationCreateFeature.h
PartSet_OperationEditConstraint.h
PartSet_FeaturePointPrs.cpp
PartSet_Listener.cpp
PartSet_Module.cpp
- PartSet_OperationConstraint.cpp
PartSet_OperationCreateConstraint.cpp
PartSet_OperationCreateFeature.cpp
PartSet_OperationEditConstraint.cpp
PartSet_SelectionMode aMode = theMode;
switch (theMode)
{
- case SM_FirstPoint: {
- //PartSet_Tools::setFeaturePoint(feature(), theX, theY, CIRCLE_ATTR_CENTER);
- //aMode = SM_SecondPoint;
- }
- break;
case SM_SecondPoint: {
boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr =
std::string PartSet_FeatureLengthPrs::getAttribute(const PartSet_SelectionMode& theMode) const
{
- std::string aAttribute;
- switch (theMode)
- {
- case SM_FirstPoint:
- //aAttribute = CIRCLE_ATTR_CENTER;
- break;
- case SM_SecondPoint:
- //aAttribute = CIRCLE_ATTR_RADIUS;
- break;
- default:
- break;
- }
- return aAttribute;
+ return "";
}
PartSet_SelectionMode PartSet_FeatureLengthPrs::getNextMode(const std::string& theAttribute) const
{
- PartSet_SelectionMode aMode = SM_SecondPoint;
-
- /*if (theAttribute == CIRCLE_ATTR_CENTER)
- aMode = SM_SecondPoint;
- else if (theAttribute == CIRCLE_ATTR_RADIUS)
- aMode = SM_DonePoint;*/
- return aMode;
+ return SM_FirstPoint;
}
void PartSet_FeatureLengthPrs::move(double theDeltaX, double theDeltaY)
{
- /*boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
- if (!aData->isValid())
- return;
-
- boost::shared_ptr<GeomDataAPI_Point2D> aPoint1 =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(CIRCLE_ATTR_CENTER));
- aPoint1->setValue(aPoint1->x() + theDeltaX, aPoint1->y() + theDeltaY);*/
}
double PartSet_FeatureLengthPrs::distanceToPoint(FeaturePtr theFeature,
double theX, double theY)
{
- /*double aDelta = 0;
- if (!theFeature || theFeature->getKind() != getKind())
- return aDelta;
-
- boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
- boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(CIRCLE_ATTR_CENTER));
-
- boost::shared_ptr<GeomAPI_Pnt2d> aPoint2d(new GeomAPI_Pnt2d(theX, theY));
- return aPoint->pnt()->distance(aPoint2d);*/
return 0;
}
double theX, double theY)
{
boost::shared_ptr<GeomDataAPI_Point2D> aPoint2D;
- /*if (!theFeature || theFeature->getKind() != getKind())
- return aPoint2D;
-
- boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
- boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(CIRCLE_ATTR_CENTER));
- if (fabs(aPoint->x() - theX) < Precision::Confusion() && fabs(aPoint->y() - theY) < Precision::Confusion() )
- aPoint2D = aPoint;
-*/
return aPoint2D;
}
boost::shared_ptr<GeomDataAPI_Point2D> PartSet_FeatureLengthPrs::featurePoint
(const PartSet_SelectionMode& theMode)
{
- /*std::string aPointArg;
- switch (theMode)
- {
- case SM_FirstPoint:
- aPointArg = CIRCLE_ATTR_CENTER;
- 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;
- */
return boost::shared_ptr<GeomDataAPI_Point2D>();
}
#include <PartSet_OperationCreateFeature.h>
#include <PartSet_OperationEditFeature.h>
#include <PartSet_OperationEditConstraint.h>
-#include <PartSet_OperationConstraint.h>
#include <PartSet_OperationCreateConstraint.h>
#include <ModuleBase_Operation.h>
#include <ModuleBase_OperationDescription.h>
anOperation = new PartSet_OperationCreateConstraint(theCmdId.c_str(), this, aSketch);
else if (theCmdId == PartSet_OperationEditConstraint::Type())
anOperation = new PartSet_OperationEditConstraint(theCmdId.c_str(), this, aSketch);
- else if (theCmdId == PartSet_OperationConstraint::Type())
- anOperation = new PartSet_OperationConstraint(theCmdId.c_str(), this, aSketch);
}
if (!anOperation) {
+++ /dev/null
-// File: PartSet_OperationConstraint.h
-// Created: 20 Apr 2014
-// Author: Natalia ERMOLAEVA
-
-#include <PartSet_OperationConstraint.h>
-
-#include <PartSet_Tools.h>
-#include <PartSet_OperationSketch.h>
-#include <SketchPlugin_ConstraintLength.h>
-
-#include <SketchPlugin_Feature.h>
-#include <SketchPlugin_Sketch.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 <ModelAPI_AttributeDouble.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_OperationConstraint::PartSet_OperationConstraint(const QString& theId,
- QObject* theParent,
- FeaturePtr theFeature)
-: PartSet_OperationSketchBase(theId, theParent), mySketch(theFeature)
-{
-}
-
-PartSet_OperationConstraint::~PartSet_OperationConstraint()
-{
-}
-
-std::string PartSet_OperationConstraint::Type()
-{
- return SKETCH_CONSTRAINT_LENGTH_KIND;
-}
-
-bool PartSet_OperationConstraint::isGranted(ModuleBase_IOperation* theOperation) const
-{
- return theOperation->getDescription()->operationId().toStdString() == PartSet_OperationSketch::Type();
-}
-
-void PartSet_OperationConstraint::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_OperationConstraint::sketch() const
-{
- return mySketch;
-}
-
-void PartSet_OperationConstraint::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView,
- const std::list<XGUI_ViewerPrs>& theSelected,
- const std::list<XGUI_ViewerPrs>& /*theHighlighted*/)
-{
- if (theSelected.empty()) {
- }
- else {
- XGUI_ViewerPrs aPrs = theSelected.front();
- FeaturePtr aFeature = aPrs.feature();
-
- setFeature(aFeature);
- setValue(120);
- flushUpdated();
- }
-}
-
-void PartSet_OperationConstraint::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
-{
-}
-
-void PartSet_OperationConstraint::startOperation()
-{
- PartSet_OperationSketchBase::startOperation();
- //setPointSelectionMode(!myInitPoint ? SM_FirstPoint : SM_SecondPoint);
-
- emit multiSelectionEnabled(false);
-}
-
-void PartSet_OperationConstraint::abortOperation()
-{
- emit featureConstructed(feature(), FM_Hide);
- PartSet_OperationSketchBase::abortOperation();
-}
-
-void PartSet_OperationConstraint::stopOperation()
-{
- PartSet_OperationSketchBase::stopOperation();
- emit multiSelectionEnabled(true);
-}
-
-void PartSet_OperationConstraint::afterCommitOperation()
-{
- PartSet_OperationSketchBase::afterCommitOperation();
- emit featureConstructed(feature(), FM_Deactivation);
-}
-
-FeaturePtr PartSet_OperationConstraint::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));
- PartSet_Tools::createConstraint(myInitPoint, aPoint);
- }*/
-
- emit featureConstructed(aNewFeature, FM_Activation);
- if (theFlushMessage)
- flushCreated();
- return aNewFeature;
-}
-
-void PartSet_OperationConstraint::setFeature(FeaturePtr theFeature)
-{
- if (!theFeature || theFeature->getKind() != SKETCH_LINE_KIND)
- return;
-
- boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
-
- boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr =
- boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_A));
- anAttr->setFeature(theFeature);
-}
-
-void PartSet_OperationConstraint::setValue(const double theValue)
-{
- boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
-
- AttributeDoublePtr anAttr =
- boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_VALUE));
- anAttr->setValue(theValue);
-
-}
+++ /dev/null
-// File: PartSet_OperationConstraint.h
-// Created: 20 Apr 2014
-// Author: Natalia ERMOLAEVA
-
-#ifndef PartSet_OperationConstraint_H
-#define PartSet_OperationConstraint_H
-
-#include "PartSet.h"
-
-#include <PartSet_OperationSketchBase.h>
-
-#include <QObject>
-
-/*!
- \class PartSet_OperationConstraint
- * \brief The operation for the sketch constraint feature creation
-*/
-class PARTSET_EXPORT PartSet_OperationConstraint : public PartSet_OperationSketchBase
-{
- Q_OBJECT
-
-public:
- /// Returns the operation type key
- static std::string Type();
-
-public:
- /// Constructor
- /// \param theId the feature identifier
- /// \param theParent the operation parent
- /// \param theFeature the parent feature
- PartSet_OperationConstraint(const QString& theId, QObject* theParent,
- FeaturePtr theSketchFeature);
- /// Destructor
- virtual ~PartSet_OperationConstraint();
-
- /// 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;
-
- /// 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);
-
-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);
-
- /// Set the feature for the constraint
- /// \param theFeature the line feature
- void setFeature(FeaturePtr theFeature);
-
- /// Set the value for the constraint
- /// \param theValue the constraint value
- void setValue(const double theValue);
-
-private:
- FeaturePtr mySketch; ///< the sketch feature
-};
-
-#endif
#include <PartSet_Tools.h>
#include <PartSet_OperationSketch.h>
#include <PartSet_EditLine.h>
+#include <PartSet_FeaturePrs.h>
#include <SketchPlugin_ConstraintLength.h>
#include <ModuleBase_OperationDescription.h>
FeaturePtr theFeature)
: PartSet_OperationSketchBase(theId, theParent), mySketch(theFeature), myIsBlockedSelection(false)
{
+ std::string aKind = theId.toStdString();
+ myFeaturePrs = PartSet_Tools::createFeaturePrs(aKind, theFeature);
+
// changed
myEditor = new PartSet_EditLine(0);
connect(myEditor, SIGNAL(stopped(double)), this, SLOT(onEditStopped(double)));
}
void PartSet_OperationEditConstraint::mousePressed(QMouseEvent* theEvent, Handle(V3d_View) theView,
- const std::list<XGUI_ViewerPrs>& /*theSelected*/,
+ const std::list<XGUI_ViewerPrs>& theSelected,
const std::list<XGUI_ViewerPrs>& theHighlighted)
{
//if (myFeatures.size() == 1)
FeaturePtr aFeature;
if (!theHighlighted.empty())
aFeature = theHighlighted.front().feature();
+ if (!aFeature && !theSelected.empty()) // changed
+ aFeature = theSelected.front().feature();
if (aFeature && aFeature == feature()) { // continue the feature edit
}
double aX, anY;
PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
- double aDeltaX = aX - aCurX;
+ /*double aDeltaX = aX - aCurX;
double aDeltaY = anY - aCurY;
- PartSet_Tools::moveFeature(feature(), aDeltaX, aDeltaY);
+ PartSet_Tools::moveFeature(feature(), aDeltaX, aDeltaY);*/
+ myFeaturePrs->setPoint(aX, anY, SM_SecondPoint);
+
/*std::list<XGUI_ViewerPrs>::const_iterator anIt = myFeatures.begin(), aLast = myFeatures.end();
for (; anIt != aLast; anIt++) {
#include <QObject>
class PartSet_EditLine;
+class PartSet_FeaturePrs;
class QMouseEvent;
/*!
private:
PartSet_EditLine* myEditor; ///< the constraint value editor
+ boost::shared_ptr<PartSet_FeaturePrs> myFeaturePrs; ///< the feature presentation
FeaturePtr mySketch; ///< the sketch feature
//std::list<XGUI_ViewerPrs> myFeatures; ///< the features to apply the edit operation
Point myCurPoint; ///< the current 3D point clicked or moved