1 // File: PartSet_OperationFeatureCreate.h
2 // Created: 20 Apr 2014
3 // Author: Natalia ERMOLAEVA
5 #include <PartSet_OperationFeatureCreate.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_OperationFeatureCreate::PartSet_OperationFeatureCreate(const QString& theId,
47 FeaturePtr theFeature)
48 : PartSet_OperationFeatureBase(theId, theParent, theFeature)
52 PartSet_OperationFeatureCreate::~PartSet_OperationFeatureCreate()
56 bool PartSet_OperationFeatureCreate::canProcessKind(const std::string& theId)
58 return theId == SketchPlugin_Line::ID() || theId == SketchPlugin_Point::ID()
59 || theId == SketchPlugin_Circle::ID() || theId == SketchPlugin_Arc::ID()
60 || theId == SketchPlugin_ConstraintDistance::ID()
61 || theId == SketchPlugin_ConstraintLength::ID()
62 || theId == SketchPlugin_ConstraintRadius::ID()
63 || theId == SketchPlugin_ConstraintParallel::ID()
64 || theId == SketchPlugin_ConstraintPerpendicular::ID()
65 || theId == SketchPlugin_ConstraintCoincidence::ID();
68 bool PartSet_OperationFeatureCreate::canBeCommitted() const
70 if (PartSet_OperationSketchBase::canBeCommitted())
71 return !myActiveWidget;
75 std::list<int> PartSet_OperationFeatureCreate::getSelectionModes(ObjectPtr theFeature) const
77 std::list<int> aModes;
78 if (theFeature != feature())
79 aModes = PartSet_OperationSketchBase::getSelectionModes(theFeature);
83 void PartSet_OperationFeatureCreate::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
86 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView);
87 PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
88 setWidgetValue(feature(), aX, anY);
92 void PartSet_OperationFeatureCreate::keyReleased(const int theKey)
97 // it start a new line creation at a free point
98 restartOperation(feature()->getKind());
106 void PartSet_OperationFeatureCreate::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView,
107 const std::list<ModuleBase_ViewerPrs>& theSelected,
108 const std::list<ModuleBase_ViewerPrs>& /*theHighlighted*/)
110 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView);
111 double aX = aPoint.X(), anY = aPoint.Y();
112 bool isClosedContour = false;
114 if (theSelected.empty()) {
115 PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
117 ModuleBase_ViewerPrs aPrs = theSelected.front();
118 const TopoDS_Shape& aShape = aPrs.shape();
119 if (!aShape.IsNull()) {
120 if (aShape.ShapeType() == TopAbs_VERTEX) { // a point is selected
121 const TopoDS_Vertex& aVertex = TopoDS::Vertex(aShape);
122 if (!aVertex.IsNull()) {
123 aPoint = BRep_Tool::Pnt(aVertex);
124 PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
125 PartSet_Tools::setConstraints(sketch(), feature(), myActiveWidget->attributeID(), aX, anY);
126 isClosedContour = true;
128 } else if (aShape.ShapeType() == TopAbs_EDGE) { // a line is selected
129 PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
134 if (!theSelected.empty()) {
135 ModuleBase_ViewerPrs aPrs = theSelected.front();
136 aFeature = aPrs.object();
138 aFeature = feature(); // for the widget distance only
141 bool isApplyed = setWidgetValue(aFeature, aX, anY);
144 emit activateNextWidget(myActiveWidget);
147 if (commit() && !isClosedContour) {
148 // if the point creation is finished, the next mouse release should commit the modification
149 // the next release can happens by double click in the viewer
150 restartOperation(feature()->getKind(), feature());
155 void PartSet_OperationFeatureCreate::activateNextToCurrentWidget()
157 emit activateNextWidget(myActiveWidget);
160 void PartSet_OperationFeatureCreate::startOperation()
162 PartSet_OperationSketchBase::startOperation();
163 //setPointSelectionMode(!myInitFeature ? SM_FirstPoint : SM_SecondPoint);
165 emit multiSelectionEnabled(false);
168 void PartSet_OperationFeatureCreate::abortOperation()
170 emit featureConstructed(feature(), FM_Hide);
171 PartSet_OperationSketchBase::abortOperation();
174 void PartSet_OperationFeatureCreate::stopOperation()
176 PartSet_OperationSketchBase::stopOperation();
177 emit multiSelectionEnabled(true);
180 void PartSet_OperationFeatureCreate::afterCommitOperation()
182 PartSet_OperationSketchBase::afterCommitOperation();
183 emit featureConstructed(feature(), FM_Deactivation);
186 FeaturePtr PartSet_OperationFeatureCreate::createFeature(const bool theFlushMessage)
188 FeaturePtr aNewFeature = ModuleBase_Operation::createFeature(false);
190 boost::shared_ptr<SketchPlugin_Feature> aFeature = boost::dynamic_pointer_cast<
191 SketchPlugin_Feature>(sketch());
193 aFeature->addSub(aNewFeature);
195 //myFeaturePrs->init(aNewFeature);
196 //myFeaturePrs->setFeature(myInitFeature, SM_FirstPoint);
198 //TODO emit featureConstructed(aNewFeature, FM_Activation);