1 // File: PartSet_OperationSketch.h
2 // Created: 20 Apr 2014
3 // Author: Natalia ERMOLAEVA
5 #include <PartSet_OperationSketch.h>
7 #include <PartSet_OperationEditLine.h>
9 #include <SketchPlugin_Sketch.h>
10 #include <ModelAPI_Data.h>
11 #include <ModelAPI_AttributeDouble.h>
12 #include <GeomAlgoAPI_FaceBuilder.h>
13 #include <GeomDataAPI_Point.h>
14 #include <GeomDataAPI_Dir.h>
16 #include <XGUI_ViewerPrs.h>
18 #include <AIS_Shape.hxx>
19 #include <AIS_ListOfInteractive.hxx>
20 #include <V3d_View.hxx>
28 PartSet_OperationSketch::PartSet_OperationSketch(const QString& theId,
30 : PartSet_OperationSketchBase(theId, theParent), myIsEditMode(false)
34 PartSet_OperationSketch::~PartSet_OperationSketch()
38 std::list<int> PartSet_OperationSketch::getSelectionModes(boost::shared_ptr<ModelAPI_Feature> theFeature) const
40 std::list<int> aModes;
42 aModes.push_back(TopAbs_FACE);
44 aModes.push_back(TopAbs_VERTEX);
45 aModes.push_back(TopAbs_EDGE);
50 void PartSet_OperationSketch::mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
51 const std::list<XGUI_ViewerPrs>& theSelected)
53 if (theSelected.empty())
55 XGUI_ViewerPrs aPrs = theSelected.front();
58 const TopoDS_Shape& aShape = aPrs.shape();
59 if (!aShape.IsNull()) {
60 setSketchPlane(aShape);
66 emit launchOperation(PartSet_OperationEditLine::Type(), aPrs.feature());
70 void PartSet_OperationSketch::setSketchPlane(const TopoDS_Shape& theShape)
72 if (theShape.IsNull())
76 boost::shared_ptr<GeomAPI_Shape> aGShape(new GeomAPI_Shape);
77 aGShape->setImpl(new TopoDS_Shape(theShape));
79 // get plane parameters
80 boost::shared_ptr<GeomAPI_Pln> aPlane = GeomAlgoAPI_FaceBuilder::plane(aGShape);
82 // set plane parameters to feature
83 boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
84 double anA, aB, aC, aD;
85 aPlane->coefficients(anA, aB, aC, aD);
87 boost::shared_ptr<ModelAPI_AttributeDouble> anAttr;
89 aData->real(SKETCH_ATTR_PLANE_A)->setValue(anA);
90 aData->real(SKETCH_ATTR_PLANE_B)->setValue(aB);
91 aData->real(SKETCH_ATTR_PLANE_C)->setValue(aC);
92 aData->real(SKETCH_ATTR_PLANE_D)->setValue(aD);
94 // temporary solution for main planes only
95 boost::shared_ptr<GeomDataAPI_Point> anOrigin =
96 boost::dynamic_pointer_cast<GeomDataAPI_Point>(aData->attribute(SKETCH_ATTR_ORIGIN));
97 anOrigin->setValue(0, 0, 0);
98 boost::shared_ptr<GeomDataAPI_Dir> aNormal =
99 boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_NORM));
100 aNormal->setValue(anA, aB, aC);
101 boost::shared_ptr<GeomDataAPI_Dir> aDirX =
102 boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_DIRX));
103 aDirX->setValue(aB, aC, anA);
104 boost::shared_ptr<GeomDataAPI_Dir> aDirY =
105 boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_DIRY));
106 aDirY->setValue(aC, anA, aB);
107 boost::shared_ptr<GeomAPI_Dir> aDir = aPlane->direction();
108 emit planeSelected(aDir->x(), aDir->y(), aDir->z());