1 // File: PartSet_OperationSketch.h
2 // Created: 20 Apr 2014
3 // Author: Natalia ERMOLAEVA
5 #include <PartSet_OperationSketch.h>
7 #include <SketchPlugin_Sketch.h>
8 #include <ModelAPI_Data.h>
9 #include <ModelAPI_AttributeDouble.h>
10 #include <GeomAlgoAPI_FaceBuilder.h>
11 #include <GeomDataAPI_Point.h>
12 #include <GeomDataAPI_Dir.h>
14 #include <AIS_Shape.hxx>
15 #include <AIS_ListOfInteractive.hxx>
23 PartSet_OperationSketch::PartSet_OperationSketch(const QString& theId,
25 : PartSet_OperationSketchBase(theId, theParent)
29 PartSet_OperationSketch::~PartSet_OperationSketch()
33 std::list<int> PartSet_OperationSketch::getSelectionModes(boost::shared_ptr<ModelAPI_Feature> theFeature) const
35 std::list<int> aModes;
37 aModes.push_back(TopAbs_FACE);
41 void PartSet_OperationSketch::setSelected(boost::shared_ptr<ModelAPI_Feature> theFeature,
42 const TopoDS_Shape& theShape)
45 setSketchPlane(theShape);
49 emit launchOperation("EditLine", theFeature);
52 void PartSet_OperationSketch::setSketchPlane(const TopoDS_Shape& theShape)
55 boost::shared_ptr<GeomAPI_Shape> aGShape(new GeomAPI_Shape);
56 aGShape->setImpl(new TopoDS_Shape(theShape));
58 // get plane parameters
59 boost::shared_ptr<GeomAPI_Pln> aPlane = GeomAlgoAPI_FaceBuilder::plane(aGShape);
61 // set plane parameters to feature
62 boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
63 double anA, aB, aC, aD;
64 aPlane->coefficients(anA, aB, aC, aD);
66 boost::shared_ptr<ModelAPI_AttributeDouble> anAttr;
68 aData->real(SKETCH_ATTR_PLANE_A)->setValue(anA);
69 aData->real(SKETCH_ATTR_PLANE_B)->setValue(aB);
70 aData->real(SKETCH_ATTR_PLANE_C)->setValue(aC);
71 aData->real(SKETCH_ATTR_PLANE_D)->setValue(aD);
73 // temporary solution for main planes only
74 boost::shared_ptr<GeomDataAPI_Point> anOrigin =
75 boost::dynamic_pointer_cast<GeomDataAPI_Point>(aData->attribute(SKETCH_ATTR_ORIGIN));
76 anOrigin->setValue(0, 0, 0);
77 boost::shared_ptr<GeomDataAPI_Dir> aNormal =
78 boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_NORM));
79 aNormal->setValue(anA, aB, aC);
80 boost::shared_ptr<GeomDataAPI_Dir> aDirX =
81 boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_DIRX));
82 aDirX->setValue(aB, aC, anA);
83 boost::shared_ptr<GeomDataAPI_Dir> aDirY =
84 boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_DIRY));
85 aDirY->setValue(aC, anA, aB);
86 boost::shared_ptr<GeomAPI_Dir> aDir = aPlane->direction();
87 emit planeSelected(aDir->x(), aDir->y(), aDir->z());