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>
42 #include <QMouseEvent>
46 PartSet_OperationFeatureCreate::PartSet_OperationFeatureCreate(const QString& theId,
48 CompositeFeaturePtr theFeature)
49 : PartSet_OperationFeatureBase(theId, theParent, theFeature)
53 PartSet_OperationFeatureCreate::~PartSet_OperationFeatureCreate()
57 bool PartSet_OperationFeatureCreate::canProcessKind(const std::string& theId)
59 return theId == SketchPlugin_Line::ID() || theId == SketchPlugin_Point::ID()
60 || theId == SketchPlugin_Circle::ID() || theId == SketchPlugin_Arc::ID()
61 || theId == SketchPlugin_ConstraintDistance::ID()
62 || theId == SketchPlugin_ConstraintLength::ID()
63 || theId == SketchPlugin_ConstraintRadius::ID()
64 || theId == SketchPlugin_ConstraintParallel::ID()
65 || theId == SketchPlugin_ConstraintPerpendicular::ID()
66 || theId == SketchPlugin_ConstraintCoincidence::ID()
67 || theId == SketchPlugin_ConstraintRigid::ID();
70 bool PartSet_OperationFeatureCreate::canBeCommitted() const
72 if (PartSet_OperationSketchBase::canBeCommitted()) {
73 //if(myActiveWidget && !myActiveWidget->isComputedDefault()) {
79 void PartSet_OperationFeatureCreate::mouseMoved(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer)
82 Handle(V3d_View) aView = theViewer->activeView();
83 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
84 PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aX, anY);
85 setWidgetValue(feature(), aX, anY);
89 void PartSet_OperationFeatureCreate::keyReleased(const int theKey)
94 // it start a new line creation at a free point
96 restartOperation(feature()->getKind());
104 void PartSet_OperationFeatureCreate::mouseReleased(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer,
105 ModuleBase_ISelection* theSelection)
107 Handle(V3d_View) aView = theViewer->activeView();
108 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
109 double aX = aPoint.X(), anY = aPoint.Y();
110 bool isClosedContour = false;
112 QList<ModuleBase_ViewerPrs> aSelected = theSelection->getSelected();
114 if (aSelected.empty()) {
115 PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aX, anY);
117 ModuleBase_ViewerPrs aPrs = aSelected.first();
118 if (getViewerPoint(aPrs, theViewer, aX, anY)) {
119 ModuleBase_ModelWidget* aActiveWgt = myPropertyPanel->activeWidget();
120 PartSet_Tools::setConstraints(sketch(), feature(), aActiveWgt->attributeID(), aX, anY);
121 isClosedContour = true;
123 const TopoDS_Shape& aShape = aPrs.shape();
124 if (!aShape.IsNull() && aShape.ShapeType() == TopAbs_EDGE) { // a line is selected
125 ObjectPtr aObject = aPrs.object();
126 if (sketch()->isSub(aObject))
127 PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aX, anY);
129 // we have to create the selected edge for the current sketch
130 ResultPtr aRes = PartSet_Tools::createFixedObjectByEdge(aPrs, sketch());
131 aSelected.first().setFeature(aRes);
136 if (!aSelected.empty()) {
137 ModuleBase_ViewerPrs aPrs = aSelected.first();
138 aFeature = aPrs.object();
140 aFeature = feature(); // for the widget distance only
143 bool isApplyed = setWidgetValue(aFeature, aX, anY);
146 myPropertyPanel->activateNextWidget();
149 if (!myPropertyPanel->activeWidget()) {
150 if(commit() && !isClosedContour) {
151 // if the point creation is finished, the next mouse release should commit the modification
152 // the next release can happens by double click in the viewer
153 restartOperation(feature()->getKind(), feature());
158 void PartSet_OperationFeatureCreate::startOperation()
160 PartSet_OperationSketchBase::startOperation();
161 //emit multiSelectionEnabled(false);
164 void PartSet_OperationFeatureCreate::abortOperation()
166 emit featureConstructed(feature(), FM_Hide);
167 PartSet_OperationSketchBase::abortOperation();
170 void PartSet_OperationFeatureCreate::stopOperation()
172 PartSet_OperationSketchBase::stopOperation();
173 //emit multiSelectionEnabled(true);
176 void PartSet_OperationFeatureCreate::afterCommitOperation()
178 PartSet_OperationSketchBase::afterCommitOperation();
179 emit featureConstructed(feature(), FM_Deactivation);
182 FeaturePtr PartSet_OperationFeatureCreate::createFeature(const bool theFlushMessage,
183 CompositeFeaturePtr theCompositeFeature)
185 FeaturePtr aNewFeature = ModuleBase_Operation::createFeature(false, sketch());
193 void PartSet_OperationFeatureCreate::onWidgetActivated(ModuleBase_ModelWidget* theWidget)
195 PartSet_OperationFeatureBase::onWidgetActivated(theWidget);
196 if (myInitFeature && theWidget) {
197 ModuleBase_WidgetPoint2D* aWgt = dynamic_cast<ModuleBase_WidgetPoint2D*>(theWidget);
198 if (aWgt && aWgt->initFromPrevious(myInitFeature)) {
199 myInitFeature = FeaturePtr();
201 myPropertyPanel->activateNextWidget();