1 // File: PartSet_OperationSketchLine.h
2 // Created: 20 Apr 2014
3 // Author: Natalia ERMOLAEVA
5 #include <PartSet_OperationSketchLine.h>
7 #include <PartSet_Tools.h>
9 #include <SketchPlugin_Feature.h>
10 #include <GeomDataAPI_Point2D.h>
11 #include <ModelAPI_Data.h>
12 #include <ModelAPI_Document.h>
14 #include <SketchPlugin_Line.h>
22 PartSet_OperationSketchLine::PartSet_OperationSketchLine(const QString& theId,
24 boost::shared_ptr<ModelAPI_Feature> theFeature)
25 : PartSet_OperationSketchBase(theId, theParent), mySketch(theFeature),
26 myPointSelectionMode(SM_FirstPoint)
30 PartSet_OperationSketchLine::~PartSet_OperationSketchLine()
34 bool PartSet_OperationSketchLine::isGranted() const
39 std::list<int> PartSet_OperationSketchLine::getSelectionModes(boost::shared_ptr<ModelAPI_Feature> theFeature) const
41 return std::list<int>();
44 void PartSet_OperationSketchLine::init(boost::shared_ptr<ModelAPI_Feature> theFeature)
48 // use the last point of the previous feature as the first of the new one
49 boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
50 myInitPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_END));
53 void PartSet_OperationSketchLine::mouseReleased(const gp_Pnt& thePoint, QMouseEvent* /*theEvent*/)
55 switch (myPointSelectionMode)
58 setLinePoint(thePoint, LINE_ATTR_START);
59 myPointSelectionMode = SM_SecondPoint;
62 case SM_SecondPoint: {
63 setLinePoint(thePoint, LINE_ATTR_END);
65 emit featureConstructed(feature(), FM_Deactivation);
66 emit launchOperation(PartSet_OperationSketchLine::Type(), feature());
74 void PartSet_OperationSketchLine::mouseMoved(const gp_Pnt& thePoint, QMouseEvent* /*theEvent*/)
76 switch (myPointSelectionMode)
79 setLinePoint(thePoint, LINE_ATTR_END);
86 void PartSet_OperationSketchLine::keyReleased(const int theKey)
89 case Qt::Key_Escape: {
93 case Qt::Key_Return: {
95 emit launchOperation(PartSet_OperationSketchLine::Type(), boost::shared_ptr<ModelAPI_Feature>());
103 void PartSet_OperationSketchLine::startOperation()
105 PartSet_OperationSketchBase::startOperation();
106 myPointSelectionMode = !myInitPoint ? SM_FirstPoint : SM_SecondPoint;
109 void PartSet_OperationSketchLine::abortOperation()
111 emit featureConstructed(feature(), FM_Abort);
112 PartSet_OperationSketchBase::abortOperation();
115 boost::shared_ptr<ModelAPI_Feature> PartSet_OperationSketchLine::createFeature()
117 boost::shared_ptr<ModelAPI_Feature> aNewFeature = ModuleBase_Operation::createFeature();
119 boost::shared_ptr<SketchPlugin_Feature> aFeature =
120 boost::dynamic_pointer_cast<SketchPlugin_Feature>(mySketch);
122 aFeature->addSub(aNewFeature);
125 boost::shared_ptr<ModelAPI_Data> aData = aNewFeature->data();
126 boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
127 (aData->attribute(LINE_ATTR_START));
128 aPoint->setValue(myInitPoint->x(), myInitPoint->y());
131 emit featureConstructed(aNewFeature, FM_Activation);
135 void PartSet_OperationSketchLine::setLinePoint(const gp_Pnt& thePoint,
136 const std::string& theAttribute)
138 boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
139 boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
140 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(theAttribute));
143 PartSet_Tools::ConvertTo2D(thePoint, mySketch, aX, anY);
144 aPoint->setValue(aX, anY);