1 // File: PartSet_OperationFeatureBase.h
2 // Created: 20 Apr 2014
3 // Author: Natalia ERMOLAEVA
5 #include <PartSet_OperationFeatureBase.h>
7 #include <PartSet_Tools.h>
8 #include <PartSet_OperationSketch.h>
10 #include <SketchPlugin_Feature.h>
11 #include <SketchPlugin_Point.h>
12 #include <SketchPlugin_Line.h>
13 #include <SketchPlugin_Circle.h>
14 #include <SketchPlugin_Arc.h>
15 #include <SketchPlugin_ConstraintDistance.h>
16 #include <SketchPlugin_ConstraintLength.h>
17 #include <SketchPlugin_ConstraintRadius.h>
18 #include <SketchPlugin_ConstraintParallel.h>
19 #include <SketchPlugin_ConstraintPerpendicular.h>
20 #include <SketchPlugin_ConstraintCoincidence.h>
22 #include <GeomAPI_Pnt2d.h>
24 #include <ModuleBase_OperationDescription.h>
25 #include <ModuleBase_WidgetPoint2D.h>
26 #include <ModuleBase_WidgetValueFeature.h>
27 #include <ModuleBase_ViewerPrs.h>
29 #include <XGUI_Constants.h>
31 #include <V3d_View.hxx>
32 #include <TopoDS_Vertex.hxx>
34 #include <BRep_Tool.hxx>
41 #include <QMouseEvent>
45 PartSet_OperationFeatureBase::PartSet_OperationFeatureBase(const QString& theId,
47 FeaturePtr theFeature)
48 : PartSet_OperationSketchBase(theId, theParent),
54 PartSet_OperationFeatureBase::~PartSet_OperationFeatureBase()
58 void PartSet_OperationFeatureBase::initSelection(
59 const std::list<ModuleBase_ViewerPrs>& theSelected,
60 const std::list<ModuleBase_ViewerPrs>& /*theHighlighted*/)
62 myPreSelection = theSelected;
65 void PartSet_OperationFeatureBase::initFeature(FeaturePtr theFeature)
67 myInitFeature = theFeature;
70 FeaturePtr PartSet_OperationFeatureBase::sketch() const
75 void PartSet_OperationFeatureBase::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView,
76 const std::list<ModuleBase_ViewerPrs>& theSelected,
77 const std::list<ModuleBase_ViewerPrs>& /*theHighlighted*/)
79 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView);
80 double aX = aPoint.X(), anY = aPoint.Y();
82 if (theSelected.empty()) {
83 PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
85 ModuleBase_ViewerPrs aPrs = theSelected.front();
86 const TopoDS_Shape& aShape = aPrs.shape();
87 if (!aShape.IsNull()) {
88 if (aShape.ShapeType() == TopAbs_VERTEX) { // a point is selected
89 const TopoDS_Vertex& aVertex = TopoDS::Vertex(aShape);
90 if (!aVertex.IsNull()) {
91 aPoint = BRep_Tool::Pnt(aVertex);
92 PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
93 PartSet_Tools::setConstraints(sketch(), feature(), myActiveWidget->attributeID(), aX, anY);
95 } else if (aShape.ShapeType() == TopAbs_EDGE) { // a line is selected
96 PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
101 if (!theSelected.empty()) {
102 ModuleBase_ViewerPrs aPrs = theSelected.front();
103 aFeature = aPrs.object();
105 aFeature = feature(); // for the widget distance only
108 bool isApplyed = setWidgetValue(aFeature, aX, anY);
111 emit activateNextWidget(myActiveWidget);
116 void PartSet_OperationFeatureBase::onWidgetActivated(ModuleBase_ModelWidget* theWidget)
118 myActiveWidget = theWidget;
119 activateByPreselection();
120 if (myInitFeature && myActiveWidget) {
121 ModuleBase_WidgetPoint2D* aWgt = dynamic_cast<ModuleBase_WidgetPoint2D*>(myActiveWidget);
122 if (aWgt && aWgt->initFromPrevious(myInitFeature)) {
123 myInitFeature = FeaturePtr();
124 emit activateNextWidget(myActiveWidget);
129 void PartSet_OperationFeatureBase::activateByPreselection()
131 if ((myPreSelection.size() > 0) && myActiveWidget) {
132 const ModuleBase_ViewerPrs& aPrs = myPreSelection.front();
133 ModuleBase_WidgetValueFeature aValue;
134 aValue.setObject(aPrs.object());
135 if (myActiveWidget->setValue(&aValue)) {
136 myPreSelection.remove(aPrs);
137 emit activateNextWidget(myActiveWidget);
139 // If preselection is enough to make a valid feature - apply it immediately
146 bool PartSet_OperationFeatureBase::setWidgetValue(ObjectPtr theFeature, double theX, double theY)
150 ModuleBase_WidgetValueFeature* aValue = new ModuleBase_WidgetValueFeature();
151 aValue->setObject(theFeature);
152 aValue->setPoint(boost::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(theX, theY)));
153 bool isApplyed = myActiveWidget->setValue(aValue);
156 myIsModified = (myIsModified || isApplyed);