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>
45 #include <QMouseEvent>
49 PartSet_OperationFeatureCreate::PartSet_OperationFeatureCreate(const QString& theId,
51 CompositeFeaturePtr theFeature)
52 : PartSet_OperationFeatureBase(theId, theParent, theFeature)
56 PartSet_OperationFeatureCreate::~PartSet_OperationFeatureCreate()
60 bool PartSet_OperationFeatureCreate::canProcessKind(const std::string& theId)
62 return theId == SketchPlugin_Line::ID() || theId == SketchPlugin_Point::ID()
63 || theId == SketchPlugin_Circle::ID() || theId == SketchPlugin_Arc::ID()
64 || theId == SketchPlugin_ConstraintDistance::ID()
65 || theId == SketchPlugin_ConstraintLength::ID()
66 || theId == SketchPlugin_ConstraintRadius::ID()
67 || theId == SketchPlugin_ConstraintParallel::ID()
68 || theId == SketchPlugin_ConstraintPerpendicular::ID()
69 || theId == SketchPlugin_ConstraintCoincidence::ID()
70 || theId == SketchPlugin_ConstraintRigid::ID();
73 bool PartSet_OperationFeatureCreate::canBeCommitted() const
75 if (PartSet_OperationSketchBase::canBeCommitted()) {
76 //if(myActiveWidget && !myActiveWidget->isComputedDefault()) {
82 void PartSet_OperationFeatureCreate::mouseMoved(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer)
85 Handle(V3d_View) aView = theViewer->activeView();
86 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
87 PartSet_Tools::convertTo2D(aPoint, sketch(), aView, 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
99 restartOperation(feature()->getKind());
107 void PartSet_OperationFeatureCreate::mouseReleased(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer,
108 ModuleBase_ISelection* theSelection)
110 Handle(V3d_View) aView = theViewer->activeView();
111 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
112 double aX = aPoint.X(), anY = aPoint.Y();
113 bool isClosedContour = false;
115 QList<ModuleBase_ViewerPrs> aSelected = theSelection->getSelected();
117 if (aSelected.empty()) {
118 PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aX, anY);
120 ModuleBase_ViewerPrs aPrs = aSelected.first();
121 const TopoDS_Shape& aShape = aPrs.shape();
122 if (!aShape.IsNull()) {
123 if (aShape.ShapeType() == TopAbs_VERTEX) { // a point is selected
124 const TopoDS_Vertex& aVertex = TopoDS::Vertex(aShape);
125 if (!aVertex.IsNull()) {
126 aPoint = BRep_Tool::Pnt(aVertex);
127 PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aX, anY);
128 ModuleBase_ModelWidget* aActiveWgt = myPropertyPanel->activeWidget();
129 PartSet_Tools::setConstraints(sketch(), feature(), aActiveWgt->attributeID(), aX, anY);
130 isClosedContour = true;
132 } else if (aShape.ShapeType() == TopAbs_EDGE) { // a line is selected
133 PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aX, anY);
138 if (!aSelected.empty()) {
139 ModuleBase_ViewerPrs aPrs = aSelected.first();
140 aFeature = aPrs.object();
142 aFeature = feature(); // for the widget distance only
145 bool isApplyed = setWidgetValue(aFeature, aX, anY);
148 myPropertyPanel->activateNextWidget();
151 if (!myPropertyPanel->activeWidget()) {
152 if(commit() && !isClosedContour) {
153 // if the point creation is finished, the next mouse release should commit the modification
154 // the next release can happens by double click in the viewer
155 restartOperation(feature()->getKind(), feature());
160 void PartSet_OperationFeatureCreate::startOperation()
162 PartSet_OperationSketchBase::startOperation();
163 //emit multiSelectionEnabled(false);
166 void PartSet_OperationFeatureCreate::abortOperation()
168 emit featureConstructed(feature(), FM_Hide);
169 PartSet_OperationSketchBase::abortOperation();
172 void PartSet_OperationFeatureCreate::stopOperation()
174 PartSet_OperationSketchBase::stopOperation();
175 //emit multiSelectionEnabled(true);
178 void PartSet_OperationFeatureCreate::afterCommitOperation()
180 PartSet_OperationSketchBase::afterCommitOperation();
181 emit featureConstructed(feature(), FM_Deactivation);
184 FeaturePtr PartSet_OperationFeatureCreate::createFeature(const bool theFlushMessage,
185 CompositeFeaturePtr theCompositeFeature)
187 FeaturePtr aNewFeature = ModuleBase_Operation::createFeature(false, sketch());
195 void PartSet_OperationFeatureCreate::onWidgetActivated(ModuleBase_ModelWidget* theWidget)
197 PartSet_OperationFeatureBase::onWidgetActivated(theWidget);
198 if (myInitFeature && theWidget) {
199 ModuleBase_WidgetPoint2D* aWgt = dynamic_cast<ModuleBase_WidgetPoint2D*>(theWidget);
200 if (aWgt && aWgt->initFromPrevious(myInitFeature)) {
201 myInitFeature = FeaturePtr();
203 myPropertyPanel->activateNextWidget();