#include <SketchPlugin_Feature.h>
#include <GeomDataAPI_Point2D.h>
+#include <GeomDataAPI_Point.h>
+#include <GeomDataAPI_Dir.h>
#include <ModelAPI_Data.h>
+#include <ModelAPI_Document.h>
+#include <SketchPlugin_Sketch.h>
#include <SketchPlugin_Line.h>
#ifdef _DEBUG
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::setSelectedShapes(const NCollection_List<TopoDS_Shape>& theList,
- const gp_Pnt& thePoint)
+void PartSet_OperationSketchLine::mouseReleased(const gp_Pnt& thePoint)
{
- if (theList.IsEmpty())
- return;
-
switch (myPointSelectionMode)
{
case SM_FirstPoint: {
break;
case SM_SecondPoint: {
setLinePoint(thePoint, LINE_ATTR_END);
- commit();
+ myPointSelectionMode = SM_None;
}
break;
case SM_None: {
}
}
-void PartSet_OperationSketchLine::setMouseMovePoint(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()
void PartSet_OperationSketchLine::stopOperation()
{
PartSet_OperationSketchBase::stopOperation();
-
myPointSelectionMode = SM_None;
}
boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(theAttribute));
- double aX = thePoint.X(), anY = thePoint.Y();
+
+ double aX = 0;
+ double anY = 0;
+ convertTo2D(thePoint, 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);
+}
+
+void PartSet_OperationSketchLine::convertTo2D(const gp_Pnt& thePoint, double& theX, double& theY)
+{
+ if (!mySketch)
+ return;
+
+ boost::shared_ptr<ModelAPI_AttributeDouble> anAttr;
+ boost::shared_ptr<ModelAPI_Data> aData = mySketch->data();
+
+ boost::shared_ptr<GeomDataAPI_Point> anOrigin =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point>(aData->attribute(SKETCH_ATTR_ORIGIN));
+
+ boost::shared_ptr<GeomDataAPI_Dir> aX =
+ boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_DIRX));
+ boost::shared_ptr<GeomDataAPI_Dir> anY =
+ boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_DIRY));
+
+ gp_Pnt aVec(thePoint.X() - anOrigin->x(), thePoint.Y() - anOrigin->y(), thePoint.Z() - anOrigin->z());
+ theX = aVec.X() * aX->x() + aVec.Y() * aX->y() + aVec.Z() * aX->z();
+ theY = aVec.X() * anY->x() + aVec.Y() * anY->y() + aVec.Z() * anY->z();
+}