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)
64 boost::shared_ptr<GeomAPI_Shape> aGShape(new GeomAPI_Shape);
65 aGShape->setImpl(new TopoDS_Shape(theShape));
67 // get plane parameters
68 boost::shared_ptr<GeomAPI_Pln> aPlane = GeomAlgoAPI_FaceBuilder::plane(aGShape);
70 // set plane parameters to feature
71 boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
72 double anA, aB, aC, aD;
73 aPlane->coefficients(anA, aB, aC, aD);
75 boost::shared_ptr<ModelAPI_AttributeDouble> anAttr;
77 aData->real(SKETCH_ATTR_PLANE_A)->setValue(anA);
78 aData->real(SKETCH_ATTR_PLANE_B)->setValue(aB);
79 aData->real(SKETCH_ATTR_PLANE_C)->setValue(aC);
80 aData->real(SKETCH_ATTR_PLANE_D)->setValue(aD);
82 // temporary solution for main planes only
83 boost::shared_ptr<GeomDataAPI_Point> anOrigin =
84 boost::dynamic_pointer_cast<GeomDataAPI_Point>(aData->attribute(SKETCH_ATTR_ORIGIN));
85 anOrigin->setValue(0, 0, 0);
86 boost::shared_ptr<GeomDataAPI_Dir> aNormal =
87 boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_NORM));
88 aNormal->setValue(anA, aB, aC);
89 boost::shared_ptr<GeomDataAPI_Dir> aDirX =
90 boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_DIRX));
91 aDirX->setValue(aB, aC, anA);
92 boost::shared_ptr<GeomDataAPI_Dir> aDirY =
93 boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_DIRY));
94 aDirY->setValue(aC, anA, aB);
95 boost::shared_ptr<GeomAPI_Dir> aDir = aPlane->direction();
96 emit planeSelected(aDir->x(), aDir->y(), aDir->z());