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>
31 #include <XGUI_Constants.h>
33 #include <V3d_View.hxx>
34 #include <TopoDS_Vertex.hxx>
36 #include <BRep_Tool.hxx>
43 #include <QMouseEvent>
47 PartSet_OperationFeatureCreate::PartSet_OperationFeatureCreate(const QString& theId,
49 FeaturePtr theFeature)
50 : PartSet_OperationFeatureBase(theId, theParent, theFeature)
54 PartSet_OperationFeatureCreate::~PartSet_OperationFeatureCreate()
58 bool PartSet_OperationFeatureCreate::canProcessKind(const std::string& theId)
60 return theId == SketchPlugin_Line::ID() || theId == SketchPlugin_Point::ID()
61 || theId == SketchPlugin_Circle::ID() || theId == SketchPlugin_Arc::ID()
62 || theId == SketchPlugin_ConstraintDistance::ID()
63 || theId == SketchPlugin_ConstraintLength::ID()
64 || theId == SketchPlugin_ConstraintRadius::ID()
65 || theId == SketchPlugin_ConstraintParallel::ID()
66 || theId == SketchPlugin_ConstraintPerpendicular::ID()
67 || theId == SketchPlugin_ConstraintCoincidence::ID()
68 || theId == SketchPlugin_ConstraintRigid::ID();
71 bool PartSet_OperationFeatureCreate::canBeCommitted() const
73 if (PartSet_OperationSketchBase::canBeCommitted()) {
74 //if(myActiveWidget && !myActiveWidget->isComputedDefault()) {
80 std::list<int> PartSet_OperationFeatureCreate::getSelectionModes(ObjectPtr theFeature) const
82 std::list<int> aModes;
83 if (theFeature != feature())
84 aModes = PartSet_OperationSketchBase::getSelectionModes(theFeature);
88 void PartSet_OperationFeatureCreate::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
91 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView);
92 PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
93 setWidgetValue(feature(), aX, anY);
97 void PartSet_OperationFeatureCreate::keyReleased(const int theKey)
101 case Qt::Key_Enter: {
102 // it start a new line creation at a free point
104 restartOperation(feature()->getKind());
112 void PartSet_OperationFeatureCreate::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView,
113 const std::list<ModuleBase_ViewerPrs>& theSelected,
114 const std::list<ModuleBase_ViewerPrs>& /*theHighlighted*/)
116 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView);
117 double aX = aPoint.X(), anY = aPoint.Y();
118 bool isClosedContour = false;
120 if (theSelected.empty()) {
121 PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
123 ModuleBase_ViewerPrs aPrs = theSelected.front();
124 const TopoDS_Shape& aShape = aPrs.shape();
125 if (!aShape.IsNull()) {
126 if (aShape.ShapeType() == TopAbs_VERTEX) { // a point is selected
127 const TopoDS_Vertex& aVertex = TopoDS::Vertex(aShape);
128 if (!aVertex.IsNull()) {
129 aPoint = BRep_Tool::Pnt(aVertex);
130 PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
131 ModuleBase_ModelWidget* aActiveWgt = myPropertyPanel->activeWidget();
132 PartSet_Tools::setConstraints(sketch(), feature(), aActiveWgt->attributeID(), aX, anY);
133 isClosedContour = true;
135 } else if (aShape.ShapeType() == TopAbs_EDGE) { // a line is selected
136 PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
141 if (!theSelected.empty()) {
142 ModuleBase_ViewerPrs aPrs = theSelected.front();
143 aFeature = aPrs.object();
145 aFeature = feature(); // for the widget distance only
148 bool isApplyed = setWidgetValue(aFeature, aX, anY);
151 myPropertyPanel->activateNextWidget();
154 if (!myPropertyPanel->activeWidget()) {
155 if(commit() && !isClosedContour) {
156 // if the point creation is finished, the next mouse release should commit the modification
157 // the next release can happens by double click in the viewer
158 restartOperation(feature()->getKind(), feature());
163 void PartSet_OperationFeatureCreate::startOperation()
165 PartSet_OperationSketchBase::startOperation();
166 emit multiSelectionEnabled(false);
169 void PartSet_OperationFeatureCreate::abortOperation()
171 emit featureConstructed(feature(), FM_Hide);
172 PartSet_OperationSketchBase::abortOperation();
175 void PartSet_OperationFeatureCreate::stopOperation()
177 PartSet_OperationSketchBase::stopOperation();
178 emit multiSelectionEnabled(true);
181 void PartSet_OperationFeatureCreate::afterCommitOperation()
183 PartSet_OperationSketchBase::afterCommitOperation();
184 emit featureConstructed(feature(), FM_Deactivation);
187 FeaturePtr PartSet_OperationFeatureCreate::createFeature(const bool theFlushMessage)
189 FeaturePtr aNewFeature = ModuleBase_Operation::createFeature(false);
191 boost::shared_ptr<SketchPlugin_Feature> aFeature = boost::dynamic_pointer_cast<
192 SketchPlugin_Feature>(sketch());
194 aFeature->addSub(aNewFeature);
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();