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 CompositeFeaturePtr 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 void PartSet_OperationFeatureCreate::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
83 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView);
84 PartSet_Tools::convertTo2D(aPoint, sketch(), theView, 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, Handle(V3d_View) theView,
105 const std::list<ModuleBase_ViewerPrs>& theSelected,
106 const std::list<ModuleBase_ViewerPrs>& /*theHighlighted*/)
108 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView);
109 double aX = aPoint.X(), anY = aPoint.Y();
110 bool isClosedContour = false;
112 if (theSelected.empty()) {
113 PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
115 ModuleBase_ViewerPrs aPrs = theSelected.front();
116 const TopoDS_Shape& aShape = aPrs.shape();
117 if (!aShape.IsNull()) {
118 if (aShape.ShapeType() == TopAbs_VERTEX) { // a point is selected
119 const TopoDS_Vertex& aVertex = TopoDS::Vertex(aShape);
120 if (!aVertex.IsNull()) {
121 aPoint = BRep_Tool::Pnt(aVertex);
122 PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
123 ModuleBase_ModelWidget* aActiveWgt = myPropertyPanel->activeWidget();
124 PartSet_Tools::setConstraints(sketch(), feature(), aActiveWgt->attributeID(), aX, anY);
125 isClosedContour = true;
127 } else if (aShape.ShapeType() == TopAbs_EDGE) { // a line is selected
128 PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
133 if (!theSelected.empty()) {
134 ModuleBase_ViewerPrs aPrs = theSelected.front();
135 aFeature = aPrs.object();
137 aFeature = feature(); // for the widget distance only
140 bool isApplyed = setWidgetValue(aFeature, aX, anY);
143 myPropertyPanel->activateNextWidget();
146 if (!myPropertyPanel->activeWidget()) {
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::startOperation()
157 PartSet_OperationSketchBase::startOperation();
158 emit multiSelectionEnabled(false);
161 void PartSet_OperationFeatureCreate::abortOperation()
163 emit featureConstructed(feature(), FM_Hide);
164 PartSet_OperationSketchBase::abortOperation();
167 void PartSet_OperationFeatureCreate::stopOperation()
169 PartSet_OperationSketchBase::stopOperation();
170 emit multiSelectionEnabled(true);
173 void PartSet_OperationFeatureCreate::afterCommitOperation()
175 PartSet_OperationSketchBase::afterCommitOperation();
176 emit featureConstructed(feature(), FM_Deactivation);
179 FeaturePtr PartSet_OperationFeatureCreate::createFeature(const bool theFlushMessage,
180 CompositeFeaturePtr theCompositeFeature)
182 FeaturePtr aNewFeature = ModuleBase_Operation::createFeature(false, sketch());
190 void PartSet_OperationFeatureCreate::onWidgetActivated(ModuleBase_ModelWidget* theWidget)
192 PartSet_OperationFeatureBase::onWidgetActivated(theWidget);
193 if (myInitFeature && theWidget) {
194 ModuleBase_WidgetPoint2D* aWgt = dynamic_cast<ModuleBase_WidgetPoint2D*>(theWidget);
195 if (aWgt && aWgt->initFromPrevious(myInitFeature)) {
196 myInitFeature = FeaturePtr();
198 myPropertyPanel->activateNextWidget();