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 <AIS_Shape.hxx>
17 #include <AIS_ListOfInteractive.hxx>
25 PartSet_OperationSketch::PartSet_OperationSketch(const QString& theId,
27 : PartSet_OperationSketchBase(theId, theParent), myIsEditMode(false)
31 PartSet_OperationSketch::~PartSet_OperationSketch()
35 std::list<int> PartSet_OperationSketch::getSelectionModes(boost::shared_ptr<ModelAPI_Feature> theFeature) const
37 std::list<int> aModes;
39 aModes.push_back(TopAbs_FACE);
41 aModes.push_back(TopAbs_VERTEX);
42 aModes.push_back(TopAbs_EDGE);
47 void PartSet_OperationSketch::setSelected(boost::shared_ptr<ModelAPI_Feature> theFeature,
48 const TopoDS_Shape& theShape)
50 if (theShape.IsNull())
54 setSketchPlane(theShape);
58 emit launchOperation(PartSet_OperationEditLine::Type(), theFeature);
61 void PartSet_OperationSketch::setSketchPlane(const TopoDS_Shape& theShape)
63 if (theShape.IsNull())
67 boost::shared_ptr<GeomAPI_Shape> aGShape(new GeomAPI_Shape);
68 aGShape->setImpl(new TopoDS_Shape(theShape));
70 // get plane parameters
71 boost::shared_ptr<GeomAPI_Pln> aPlane = GeomAlgoAPI_FaceBuilder::plane(aGShape);
73 // set plane parameters to feature
74 boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
75 double anA, aB, aC, aD;
76 aPlane->coefficients(anA, aB, aC, aD);
78 boost::shared_ptr<ModelAPI_AttributeDouble> anAttr;
80 aData->real(SKETCH_ATTR_PLANE_A)->setValue(anA);
81 aData->real(SKETCH_ATTR_PLANE_B)->setValue(aB);
82 aData->real(SKETCH_ATTR_PLANE_C)->setValue(aC);
83 aData->real(SKETCH_ATTR_PLANE_D)->setValue(aD);
85 // temporary solution for main planes only
86 boost::shared_ptr<GeomDataAPI_Point> anOrigin =
87 boost::dynamic_pointer_cast<GeomDataAPI_Point>(aData->attribute(SKETCH_ATTR_ORIGIN));
88 anOrigin->setValue(0, 0, 0);
89 boost::shared_ptr<GeomDataAPI_Dir> aNormal =
90 boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_NORM));
91 aNormal->setValue(anA, aB, aC);
92 boost::shared_ptr<GeomDataAPI_Dir> aDirX =
93 boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_DIRX));
94 aDirX->setValue(aB, aC, anA);
95 boost::shared_ptr<GeomDataAPI_Dir> aDirY =
96 boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_DIRY));
97 aDirY->setValue(aC, anA, aB);
98 boost::shared_ptr<GeomAPI_Dir> aDir = aPlane->direction();
99 emit planeSelected(aDir->x(), aDir->y(), aDir->z());