1 // File: PartSet_OperationSketch.h
2 // Created: 20 Apr 2014
3 // Author: Natalia ERMOLAEVA
5 #include <PartSet_OperationSketch.h>
7 #include <PartSet_OperationEditLine.h>
8 #include <PartSet_Tools.h>
10 #include <SketchPlugin_Sketch.h>
12 #include <ModelAPI_Data.h>
13 #include <ModelAPI_AttributeDouble.h>
14 #include <ModelAPI_AttributeRefList.h>
16 #include <GeomAlgoAPI_FaceBuilder.h>
17 #include <GeomDataAPI_Point.h>
18 #include <GeomDataAPI_Dir.h>
20 #include <XGUI_ViewerPrs.h>
22 #include <AIS_Shape.hxx>
23 #include <AIS_ListOfInteractive.hxx>
24 #include <V3d_View.hxx>
30 #include <QMouseEvent>
34 PartSet_OperationSketch::PartSet_OperationSketch(const QString& theId,
36 : PartSet_OperationSketchBase(theId, theParent), myIsEditMode(false)
40 PartSet_OperationSketch::~PartSet_OperationSketch()
44 std::list<int> PartSet_OperationSketch::getSelectionModes(boost::shared_ptr<ModelAPI_Feature> theFeature) const
46 std::list<int> aModes;
48 aModes.push_back(TopAbs_FACE);
50 aModes.push_back(TopAbs_VERTEX);
51 aModes.push_back(TopAbs_EDGE);
56 void PartSet_OperationSketch::mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
57 const std::list<XGUI_ViewerPrs>& theSelected)
59 if (theSelected.empty())
63 XGUI_ViewerPrs aPrs = theSelected.front();
64 const TopoDS_Shape& aShape = aPrs.shape();
65 if (!aShape.IsNull()) {
66 setSketchPlane(aShape);
71 if (theSelected.size() == 1) {
72 boost::shared_ptr<ModelAPI_Feature> aFeature = theSelected.front().feature();
74 emit launchOperation(PartSet_OperationEditLine::Type(), aFeature);
79 void PartSet_OperationSketch::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView,
80 const std::list<XGUI_ViewerPrs>& theSelected)
82 if (!myIsEditMode || !(theEvent->buttons() & Qt::LeftButton) || theSelected.empty())
85 if (theSelected.size() != 1) {
86 boost::shared_ptr<ModelAPI_Feature> aFeature = PartSet_Tools::NearestFeature(theEvent->pos(),
87 theView, feature(), theSelected);
89 emit launchOperation(PartSet_OperationEditLine::Type(), aFeature);
93 std::map<boost::shared_ptr<ModelAPI_Feature>, boost::shared_ptr<GeomAPI_Shape> >
94 PartSet_OperationSketch::preview() const
96 std::map<boost::shared_ptr<ModelAPI_Feature>, boost::shared_ptr<GeomAPI_Shape> > aPreviewMap;
98 boost::shared_ptr<SketchPlugin_Feature> aFeature;
100 boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
101 boost::shared_ptr<ModelAPI_AttributeRefList> aRefList =
102 boost::dynamic_pointer_cast<ModelAPI_AttributeRefList>(aData->attribute(SKETCH_ATTR_FEATURES));
104 std::list<boost::shared_ptr<ModelAPI_Feature> > aFeatures = aRefList->list();
105 std::list<boost::shared_ptr<ModelAPI_Feature> >::const_iterator anIt = aFeatures.begin(),
106 aLast = aFeatures.end();
107 for (; anIt != aLast; anIt++) {
108 aFeature = boost::dynamic_pointer_cast<SketchPlugin_Feature>(*anIt);
109 boost::shared_ptr<GeomAPI_Shape> aPreview = aFeature->preview();
111 aPreviewMap[aFeature] = aPreview;
116 void PartSet_OperationSketch::setSketchPlane(const TopoDS_Shape& theShape)
118 if (theShape.IsNull())
121 // get selected shape
122 boost::shared_ptr<GeomAPI_Shape> aGShape(new GeomAPI_Shape);
123 aGShape->setImpl(new TopoDS_Shape(theShape));
125 // get plane parameters
126 boost::shared_ptr<GeomAPI_Pln> aPlane = GeomAlgoAPI_FaceBuilder::plane(aGShape);
128 // set plane parameters to feature
129 boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
130 double anA, aB, aC, aD;
131 aPlane->coefficients(anA, aB, aC, aD);
133 boost::shared_ptr<ModelAPI_AttributeDouble> anAttr;
135 aData->real(SKETCH_ATTR_PLANE_A)->setValue(anA);
136 aData->real(SKETCH_ATTR_PLANE_B)->setValue(aB);
137 aData->real(SKETCH_ATTR_PLANE_C)->setValue(aC);
138 aData->real(SKETCH_ATTR_PLANE_D)->setValue(aD);
140 // temporary solution for main planes only
141 boost::shared_ptr<GeomDataAPI_Point> anOrigin =
142 boost::dynamic_pointer_cast<GeomDataAPI_Point>(aData->attribute(SKETCH_ATTR_ORIGIN));
143 anOrigin->setValue(0, 0, 0);
144 boost::shared_ptr<GeomDataAPI_Dir> aNormal =
145 boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_NORM));
146 aNormal->setValue(anA, aB, aC);
147 boost::shared_ptr<GeomDataAPI_Dir> aDirX =
148 boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_DIRX));
149 aDirX->setValue(aB, aC, anA);
150 boost::shared_ptr<GeomDataAPI_Dir> aDirY =
151 boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_DIRY));
152 aDirY->setValue(aC, anA, aB);
153 boost::shared_ptr<GeomAPI_Dir> aDir = aPlane->direction();
154 emit planeSelected(aDir->x(), aDir->y(), aDir->z());