#include <GeomDataAPI_Point.h>
#include <GeomDataAPI_Dir.h>
#include <ModelAPI_Data.h>
+#include <ModelAPI_Document.h>
#include <SketchPlugin_Sketch.h>
#include <SketchPlugin_Line.h>
return true;
}
-int PartSet_OperationSketchLine::getSelectionMode() const
+int PartSet_OperationSketchLine::getSelectionMode(boost::shared_ptr<ModelAPI_Feature> theFeature) const
{
- return 0;//TopAbs_FACE;
+ int aMode = 0;
+ if (theFeature != feature())
+ aMode = TopAbs_VERTEX;
+ return aMode;
}
void PartSet_OperationSketchLine::mouseReleased(const gp_Pnt& thePoint)
void PartSet_OperationSketchLine::mouseMoved(const gp_Pnt& thePoint)
{
- if (myPointSelectionMode == SM_SecondPoint)
- setLinePoint(thePoint, LINE_ATTR_END);
+ switch (myPointSelectionMode)
+ {
+ 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);
+ }
+ break;
+ default:
+ break;
+ }
+}
+
+void PartSet_OperationSketchLine::keyReleased(const int theKey)
+{
+ switch (theKey) {
+ case Qt::Key_Escape:
+ abort();
+ break;
+ case Qt::Key_Enter:
+ //myPointSelectionMode = myPointSelectionMode;
+ break;
+ default:
+ break;
+ }
}
void PartSet_OperationSketchLine::startOperation()
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);
+}
+
void PartSet_OperationSketchLine::convertTo2D(const gp_Pnt& thePoint, double& theX, double& theY)
{
if (!mySketch)