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 bool PartSet_OperationSketch::isPerformedImmediately() const
38 int PartSet_OperationSketch::getSelectionMode() const
43 void PartSet_OperationSketch::setSelectedShapes(const NCollection_List<TopoDS_Shape>& theList)
45 if (theList.IsEmpty())
49 const TopoDS_Shape& aShape = theList.First();
50 boost::shared_ptr<GeomAPI_Shape> aGShape(new GeomAPI_Shape);
51 aGShape->setImpl(new TopoDS_Shape(aShape));
53 // get plane parameters
54 boost::shared_ptr<GeomAPI_Pln> aPlane = GeomAlgoAPI_FaceBuilder::plane(aGShape);
56 // set plane parameters to feature
57 boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
58 double anA, aB, aC, aD;
59 aPlane->coefficients(anA, aB, aC, aD);
61 boost::shared_ptr<ModelAPI_AttributeDouble> anAttr;
63 aData->real(SKETCH_ATTR_PLANE_A)->setValue(anA);
64 aData->real(SKETCH_ATTR_PLANE_B)->setValue(aB);
65 aData->real(SKETCH_ATTR_PLANE_C)->setValue(aC);
66 aData->real(SKETCH_ATTR_PLANE_D)->setValue(aD);
68 // temporary solution for main planes only
69 boost::shared_ptr<GeomDataAPI_Point> anOrigin =
70 boost::dynamic_pointer_cast<GeomDataAPI_Point>(aData->attribute(SKETCH_ATTR_ORIGIN));
71 anOrigin->setValue(0, 0, 0);
72 boost::shared_ptr<GeomDataAPI_Dir> aNormal =
73 boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_NORM));
74 aNormal->setValue(anA, aB, aC);
75 boost::shared_ptr<GeomDataAPI_Dir> aDirX =
76 boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_DIRX));
77 aDirX->setValue(aB, aC, anA);
78 boost::shared_ptr<GeomDataAPI_Dir> aDirY =
79 boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_DIRY));
80 aDirY->setValue(aC, anA, aB);
82 boost::shared_ptr<GeomAPI_Dir> aDir = aPlane->direction();
83 emit viewerProjectionChange(aDir->x(), aDir->y(), aDir->z());
86 //SketchPlugin_Sketch::setActive(myFeature);