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>
21 #include <SketchPlugin_ConstraintRigid.h>
23 #include <GeomAPI_Pnt2d.h>
25 #include <ModuleBase_OperationDescription.h>
26 #include <ModuleBase_WidgetPoint2D.h>
27 #include <ModuleBase_WidgetValueFeature.h>
28 #include <ModuleBase_ViewerPrs.h>
29 #include <ModuleBase_IPropertyPanel.h>
30 #include <ModuleBase_ISelection.h>
31 #include <ModuleBase_IViewer.h>
33 #include <XGUI_Constants.h>
35 #include <V3d_View.hxx>
36 #include <TopoDS_Vertex.hxx>
38 #include <BRep_Tool.hxx>
46 #include <QMouseEvent>
50 PartSet_OperationFeatureCreate::PartSet_OperationFeatureCreate(const QString& theId,
52 CompositeFeaturePtr theFeature)
53 : PartSet_OperationFeatureBase(theId, theParent, theFeature)
57 PartSet_OperationFeatureCreate::~PartSet_OperationFeatureCreate()
61 bool PartSet_OperationFeatureCreate::canProcessKind(const std::string& theId)
63 return theId == SketchPlugin_Line::ID() || theId == SketchPlugin_Point::ID()
64 || theId == SketchPlugin_Circle::ID() || theId == SketchPlugin_Arc::ID()
65 || theId == SketchPlugin_ConstraintDistance::ID()
66 || theId == SketchPlugin_ConstraintLength::ID()
67 || theId == SketchPlugin_ConstraintRadius::ID()
68 || theId == SketchPlugin_ConstraintParallel::ID()
69 || theId == SketchPlugin_ConstraintPerpendicular::ID()
70 || theId == SketchPlugin_ConstraintCoincidence::ID()
71 || theId == SketchPlugin_ConstraintRigid::ID();
74 bool PartSet_OperationFeatureCreate::canBeCommitted() const
76 if (PartSet_OperationSketchBase::canBeCommitted()) {
77 //if(myActiveWidget && !myActiveWidget->isComputedDefault()) {
83 void PartSet_OperationFeatureCreate::mouseMoved(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer)
86 Handle(V3d_View) aView = theViewer->activeView();
87 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
88 PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aX, anY);
89 setWidgetValue(feature(), aX, anY);
93 void PartSet_OperationFeatureCreate::keyReleased(const int theKey)
98 // it start a new line creation at a free point
100 restartOperation(feature()->getKind());
108 void PartSet_OperationFeatureCreate::mouseReleased(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer,
109 ModuleBase_ISelection* theSelection)
111 Handle(V3d_View) aView = theViewer->activeView();
112 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
113 double aX = aPoint.X(), anY = aPoint.Y();
114 bool isClosedContour = false;
116 QList<ModuleBase_ViewerPrs> aSelected = theSelection->getSelected();
118 if (aSelected.empty()) {
119 PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aX, anY);
121 ModuleBase_ViewerPrs aPrs = aSelected.first();
122 const TopoDS_Shape& aShape = aPrs.shape();
123 if (!aShape.IsNull()) {
124 if (aShape.ShapeType() == TopAbs_VERTEX) { // a point is selected
125 const TopoDS_Vertex& aVertex = TopoDS::Vertex(aShape);
126 if (!aVertex.IsNull()) {
127 aPoint = BRep_Tool::Pnt(aVertex);
128 PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aX, anY);
129 ModuleBase_ModelWidget* aActiveWgt = myPropertyPanel->activeWidget();
130 PartSet_Tools::setConstraints(sketch(), feature(), aActiveWgt->attributeID(), aX, anY);
131 isClosedContour = true;
133 } else if (aShape.ShapeType() == TopAbs_EDGE) { // a line is selected
134 ObjectPtr aObject = aPrs.object();
135 if (sketch()->isSub(aObject))
136 PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aX, anY);
138 // we have to create the selected edge for the current sketch
139 ResultPtr aRes = PartSet_Tools::createFixedObjectByEdge(aPrs, sketch());
140 aSelected.first().setFeature(aRes);
146 if (!aSelected.empty()) {
147 ModuleBase_ViewerPrs aPrs = aSelected.first();
148 aFeature = aPrs.object();
150 aFeature = feature(); // for the widget distance only
153 bool isApplyed = setWidgetValue(aFeature, aX, anY);
156 myPropertyPanel->activateNextWidget();
159 if (!myPropertyPanel->activeWidget()) {
160 if(commit() && !isClosedContour) {
161 // if the point creation is finished, the next mouse release should commit the modification
162 // the next release can happens by double click in the viewer
163 restartOperation(feature()->getKind(), feature());
168 void PartSet_OperationFeatureCreate::startOperation()
170 PartSet_OperationSketchBase::startOperation();
171 //emit multiSelectionEnabled(false);
174 void PartSet_OperationFeatureCreate::abortOperation()
176 emit featureConstructed(feature(), FM_Hide);
177 PartSet_OperationSketchBase::abortOperation();
180 void PartSet_OperationFeatureCreate::stopOperation()
182 PartSet_OperationSketchBase::stopOperation();
183 //emit multiSelectionEnabled(true);
186 void PartSet_OperationFeatureCreate::afterCommitOperation()
188 PartSet_OperationSketchBase::afterCommitOperation();
189 emit featureConstructed(feature(), FM_Deactivation);
192 FeaturePtr PartSet_OperationFeatureCreate::createFeature(const bool theFlushMessage,
193 CompositeFeaturePtr theCompositeFeature)
195 FeaturePtr aNewFeature = ModuleBase_Operation::createFeature(false, sketch());
203 void PartSet_OperationFeatureCreate::onWidgetActivated(ModuleBase_ModelWidget* theWidget)
205 PartSet_OperationFeatureBase::onWidgetActivated(theWidget);
206 if (myInitFeature && theWidget) {
207 ModuleBase_WidgetPoint2D* aWgt = dynamic_cast<ModuleBase_WidgetPoint2D*>(theWidget);
208 if (aWgt && aWgt->initFromPrevious(myInitFeature)) {
209 myInitFeature = FeaturePtr();
211 myPropertyPanel->activateNextWidget();