std::list<int> PartSet_OperationSketchLine::getSelectionModes(boost::shared_ptr<ModelAPI_Feature> theFeature) const
{
- std::list<int> aModes;
- if (theFeature != feature()) {
- aModes.push_back(TopAbs_VERTEX);
- aModes.push_back(TopAbs_EDGE);
- }
- return aModes;
+ return std::list<int>();
+}
+
+void PartSet_OperationSketchLine::init(boost::shared_ptr<ModelAPI_Feature> theFeature)
+{
+ if (!theFeature)
+ 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));
}
void PartSet_OperationSketchLine::mouseReleased(const gp_Pnt& thePoint, QMouseEvent* /*theEvent*/)
break;
case SM_SecondPoint: {
setLinePoint(thePoint, LINE_ATTR_END);
- myPointSelectionMode = SM_None;
- }
- break;
- case SM_None: {
+ commit();
+ emit featureConstructed(feature(), FM_Deactivation);
+ emit launchOperation(PartSet_OperationSketchLine::Type(), feature());
}
break;
default:
case SM_SecondPoint:
setLinePoint(thePoint, LINE_ATTR_END);
break;
- case SM_None: {
- boost::shared_ptr<ModelAPI_Feature> aPrevFeature = feature();
- // stop the last operation
- commitOperation();
- document()->finishOperation();
- //emit changeSelectionMode(aPrevFeature, TopAbs_VERTEX);
- // start a new operation
- document()->startOperation();
- startOperation();
- // use the last point of the previous feature as the first of the new one
- setLinePoint(aPrevFeature, LINE_ATTR_END, LINE_ATTR_START);
- myPointSelectionMode = SM_SecondPoint;
-
- emit featureConstructed(aPrevFeature, FM_Deactivation);
- }
- break;
default:
break;
}
{
switch (theKey) {
case Qt::Key_Escape: {
- if (myPointSelectionMode != SM_None)
- emit featureConstructed(feature(), FM_Abort);
abort();
}
break;
case Qt::Key_Return: {
- if (myPointSelectionMode != SM_None) {
- emit featureConstructed(feature(), FM_Abort);
- myPointSelectionMode = SM_FirstPoint;
- document()->abortOperation();
- }
- else
- myPointSelectionMode = SM_FirstPoint;
+ abort();
+ emit launchOperation(PartSet_OperationSketchLine::Type(), boost::shared_ptr<ModelAPI_Feature>());
}
break;
default:
void PartSet_OperationSketchLine::startOperation()
{
PartSet_OperationSketchBase::startOperation();
- myPointSelectionMode = SM_FirstPoint;
+ myPointSelectionMode = !myInitPoint ? SM_FirstPoint : SM_SecondPoint;
}
-void PartSet_OperationSketchLine::stopOperation()
+void PartSet_OperationSketchLine::abortOperation()
{
- PartSet_OperationSketchBase::stopOperation();
- myPointSelectionMode = SM_None;
+ emit featureConstructed(feature(), FM_Abort);
+ PartSet_OperationSketchBase::abortOperation();
}
boost::shared_ptr<ModelAPI_Feature> PartSet_OperationSketchLine::createFeature()
aFeature->addSub(aNewFeature);
}
+ if (myInitPoint) {
+ 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));
+ aPoint->setValue(myInitPoint->x(), myInitPoint->y());
+ }
+
emit featureConstructed(aNewFeature, FM_Activation);
return aNewFeature;
}
PartSet_Tools::ConvertTo2D(thePoint, mySketch, aX, anY);
aPoint->setValue(aX, anY);
}
-
-void PartSet_OperationSketchLine::setLinePoint(boost::shared_ptr<ModelAPI_Feature> theSourceFeature,
- const std::string& theSourceAttribute,
- const std::string& theAttribute)
-{
- boost::shared_ptr<ModelAPI_Data> aData = theSourceFeature->data();
- boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(theSourceAttribute));
- double aX = aPoint->x();
- double anY = aPoint->y();
-
- aData = feature()->data();
- aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(theAttribute));
- aPoint->setValue(aX, anY);
-}
#include <PartSet_OperationSketchBase.h>
#include <QObject>
+class GeomDataAPI_Point2D;
class QMouseEvent;
/*!
/// \return the selection mode
virtual std::list<int> getSelectionModes(boost::shared_ptr<ModelAPI_Feature> theFeature) const;
+ /// Initializes some fields accorging to the feature
+ /// \param theFeature the feature
+ virtual void init(boost::shared_ptr<ModelAPI_Feature> theFeature);
+
/// Gives the current selected objects to be processed by the operation
/// \param thePoint a point clicked in the viewer
/// \param theEvent the mouse event
/// After the parent operation body perform, set sketch feature to the created line feature
virtual void startOperation();
- /// \brief Virtual method called when operation is started
- /// Virtual method called when operation stopped - committed or aborted.
- /// After the parent operation body perform, reset selection point mode of the operation
- virtual void stopOperation();
+ /// 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();
/// Creates an operation new feature
/// In addition to the default realization it appends the created line feature to
/// \param theAttribute the start or end attribute of the line
void setLinePoint(const gp_Pnt& thePoint, const std::string& theAttribute);
- /// \brief Set the point to the line by the point of the source line.
- /// \param theSourceFeature the feature, where the point is obtained
- /// \param theSourceAttribute the start or end attribute of the source line
- /// \param theAttribute the start or end attribute of the line
- void setLinePoint(boost::shared_ptr<ModelAPI_Feature> theSourceFeature,
- const std::string& theSourceAttribute,
- const std::string& theAttribute);
-
protected:
///< Structure to lists the possible types of point selection modes
- enum PointSelectionMode {SM_FirstPoint, SM_SecondPoint, SM_None};
+ enum PointSelectionMode {SM_FirstPoint, SM_SecondPoint};
private:
boost::shared_ptr<ModelAPI_Feature> mySketch; ///< the sketch feature
+ boost::shared_ptr<GeomDataAPI_Point2D> myInitPoint; ///< the first line point
PointSelectionMode myPointSelectionMode; ///< point selection mode
};