1 // File: PartSet_OperationSketch.h
2 // Created: 20 Apr 2014
3 // Author: Natalia ERMOLAEVA
5 #include <PartSet_OperationSketch.h>
7 #include <PartSet_OperationEditLine.h>
8 #include <PartSet_Tools.h>
10 #include <SketchPlugin_Sketch.h>
12 #include <ModelAPI_Data.h>
13 #include <ModelAPI_AttributeDouble.h>
14 #include <GeomAlgoAPI_FaceBuilder.h>
15 #include <GeomDataAPI_Point.h>
16 #include <GeomDataAPI_Dir.h>
18 #include <XGUI_ViewerPrs.h>
20 #include <AIS_Shape.hxx>
21 #include <AIS_ListOfInteractive.hxx>
22 #include <V3d_View.hxx>
28 #include <QMouseEvent>
32 PartSet_OperationSketch::PartSet_OperationSketch(const QString& theId,
34 : PartSet_OperationSketchBase(theId, theParent), myIsEditMode(false)
38 PartSet_OperationSketch::~PartSet_OperationSketch()
42 std::list<int> PartSet_OperationSketch::getSelectionModes(boost::shared_ptr<ModelAPI_Feature> theFeature) const
44 std::list<int> aModes;
46 aModes.push_back(TopAbs_FACE);
48 aModes.push_back(TopAbs_VERTEX);
49 aModes.push_back(TopAbs_EDGE);
54 void PartSet_OperationSketch::mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
55 const std::list<XGUI_ViewerPrs>& theSelected)
57 if (theSelected.empty())
61 XGUI_ViewerPrs aPrs = theSelected.front();
62 const TopoDS_Shape& aShape = aPrs.shape();
63 if (!aShape.IsNull()) {
64 setSketchPlane(aShape);
70 void PartSet_OperationSketch::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView,
71 const std::list<XGUI_ViewerPrs>& theSelected)
73 if (!myIsEditMode || !(theEvent->buttons() & Qt::LeftButton) || theSelected.empty())
76 boost::shared_ptr<ModelAPI_Feature> aFeature = PartSet_Tools::NearestFeature(theEvent->pos(),
77 theView, feature(), theSelected);
79 emit launchOperation(PartSet_OperationEditLine::Type(), aFeature);
82 void PartSet_OperationSketch::setSketchPlane(const TopoDS_Shape& theShape)
84 if (theShape.IsNull())
88 boost::shared_ptr<GeomAPI_Shape> aGShape(new GeomAPI_Shape);
89 aGShape->setImpl(new TopoDS_Shape(theShape));
91 // get plane parameters
92 boost::shared_ptr<GeomAPI_Pln> aPlane = GeomAlgoAPI_FaceBuilder::plane(aGShape);
94 // set plane parameters to feature
95 boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
96 double anA, aB, aC, aD;
97 aPlane->coefficients(anA, aB, aC, aD);
99 boost::shared_ptr<ModelAPI_AttributeDouble> anAttr;
101 aData->real(SKETCH_ATTR_PLANE_A)->setValue(anA);
102 aData->real(SKETCH_ATTR_PLANE_B)->setValue(aB);
103 aData->real(SKETCH_ATTR_PLANE_C)->setValue(aC);
104 aData->real(SKETCH_ATTR_PLANE_D)->setValue(aD);
106 // temporary solution for main planes only
107 boost::shared_ptr<GeomDataAPI_Point> anOrigin =
108 boost::dynamic_pointer_cast<GeomDataAPI_Point>(aData->attribute(SKETCH_ATTR_ORIGIN));
109 anOrigin->setValue(0, 0, 0);
110 boost::shared_ptr<GeomDataAPI_Dir> aNormal =
111 boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_NORM));
112 aNormal->setValue(anA, aB, aC);
113 boost::shared_ptr<GeomDataAPI_Dir> aDirX =
114 boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_DIRX));
115 aDirX->setValue(aB, aC, anA);
116 boost::shared_ptr<GeomDataAPI_Dir> aDirY =
117 boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_DIRY));
118 aDirY->setValue(aC, anA, aB);
119 boost::shared_ptr<GeomAPI_Dir> aDir = aPlane->direction();
120 emit planeSelected(aDir->x(), aDir->y(), aDir->z());