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);
43 void PartSet_OperationSketch::setSelected(boost::shared_ptr<ModelAPI_Feature> theFeature,
44 const TopoDS_Shape& theShape)
46 if (theShape.IsNull())
50 setSketchPlane(theShape);
54 emit launchOperation(PartSet_OperationEditLine::Type(), theFeature);
57 void PartSet_OperationSketch::setSketchPlane(const TopoDS_Shape& theShape)
60 boost::shared_ptr<GeomAPI_Shape> aGShape(new GeomAPI_Shape);
61 aGShape->setImpl(new TopoDS_Shape(theShape));
63 // get plane parameters
64 boost::shared_ptr<GeomAPI_Pln> aPlane = GeomAlgoAPI_FaceBuilder::plane(aGShape);
66 // set plane parameters to feature
67 boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
68 double anA, aB, aC, aD;
69 aPlane->coefficients(anA, aB, aC, aD);
71 boost::shared_ptr<ModelAPI_AttributeDouble> anAttr;
73 aData->real(SKETCH_ATTR_PLANE_A)->setValue(anA);
74 aData->real(SKETCH_ATTR_PLANE_B)->setValue(aB);
75 aData->real(SKETCH_ATTR_PLANE_C)->setValue(aC);
76 aData->real(SKETCH_ATTR_PLANE_D)->setValue(aD);
78 // temporary solution for main planes only
79 boost::shared_ptr<GeomDataAPI_Point> anOrigin =
80 boost::dynamic_pointer_cast<GeomDataAPI_Point>(aData->attribute(SKETCH_ATTR_ORIGIN));
81 anOrigin->setValue(0, 0, 0);
82 boost::shared_ptr<GeomDataAPI_Dir> aNormal =
83 boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_NORM));
84 aNormal->setValue(anA, aB, aC);
85 boost::shared_ptr<GeomDataAPI_Dir> aDirX =
86 boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_DIRX));
87 aDirX->setValue(aB, aC, anA);
88 boost::shared_ptr<GeomDataAPI_Dir> aDirY =
89 boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_DIRY));
90 aDirY->setValue(aC, anA, aB);
91 boost::shared_ptr<GeomAPI_Dir> aDir = aPlane->direction();
92 emit planeSelected(aDir->x(), aDir->y(), aDir->z());