1 // File: PartSet_OperationSketchLine.h
2 // Created: 20 Apr 2014
3 // Author: Natalia ERMOLAEVA
5 #include <PartSet_OperationSketchLine.h>
7 #include <SketchPlugin_Feature.h>
8 #include <GeomDataAPI_Point2D.h>
9 #include <GeomDataAPI_Point.h>
10 #include <GeomDataAPI_Dir.h>
11 #include <ModelAPI_Data.h>
13 #include <SketchPlugin_Sketch.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 int PartSet_OperationSketchLine::getSelectionMode() const
41 return 0;//TopAbs_FACE;
44 void PartSet_OperationSketchLine::mouseReleased(const gp_Pnt& thePoint)
46 switch (myPointSelectionMode)
49 setLinePoint(thePoint, LINE_ATTR_START);
50 myPointSelectionMode = SM_SecondPoint;
53 case SM_SecondPoint: {
54 setLinePoint(thePoint, LINE_ATTR_END);
55 myPointSelectionMode = SM_None;
67 void PartSet_OperationSketchLine::mouseMoved(const gp_Pnt& thePoint)
69 if (myPointSelectionMode == SM_SecondPoint)
70 setLinePoint(thePoint, LINE_ATTR_END);
73 void PartSet_OperationSketchLine::startOperation()
75 PartSet_OperationSketchBase::startOperation();
78 boost::shared_ptr<SketchPlugin_Feature> aFeature =
79 boost::dynamic_pointer_cast<SketchPlugin_Feature>(mySketch);
81 aFeature->addSub(feature());
83 myPointSelectionMode = SM_FirstPoint;
86 void PartSet_OperationSketchLine::stopOperation()
88 PartSet_OperationSketchBase::stopOperation();
89 myPointSelectionMode = SM_None;
92 void PartSet_OperationSketchLine::setLinePoint(const gp_Pnt& thePoint,
93 const std::string& theAttribute)
95 boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
96 boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
97 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(theAttribute));
101 convertTo2D(thePoint, aX, anY);
102 aPoint->setValue(aX, anY);
105 void PartSet_OperationSketchLine::convertTo2D(const gp_Pnt& thePoint, double& theX, double& theY)
110 boost::shared_ptr<ModelAPI_AttributeDouble> anAttr;
111 boost::shared_ptr<ModelAPI_Data> aData = mySketch->data();
113 boost::shared_ptr<GeomDataAPI_Point> anOrigin =
114 boost::dynamic_pointer_cast<GeomDataAPI_Point>(aData->attribute(SKETCH_ATTR_ORIGIN));
116 boost::shared_ptr<GeomDataAPI_Dir> aX =
117 boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_DIRX));
118 boost::shared_ptr<GeomDataAPI_Dir> anY =
119 boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_DIRY));
121 gp_Pnt aVec(thePoint.X() - anOrigin->x(), thePoint.Y() - anOrigin->y(), thePoint.Z() - anOrigin->z());
122 theX = aVec.X() * aX->x() + aVec.Y() * aX->y() + aVec.Z() * aX->z();
123 theY = aVec.X() * anY->x() + aVec.Y() * anY->y() + aVec.Z() * anY->z();