1 // File: PartSet_OperationConstraint.h
2 // Created: 20 Apr 2014
3 // Author: Natalia ERMOLAEVA
5 #include <PartSet_OperationConstraint.h>
7 #include <PartSet_Tools.h>
8 #include <PartSet_OperationSketch.h>
10 #include <SketchPlugin_Feature.h>
11 #include <SketchPlugin_Sketch.h>
13 #include <GeomDataAPI_Point2D.h>
15 #include <ModuleBase_OperationDescription.h>
17 #include <ModelAPI_Data.h>
18 #include <ModelAPI_Document.h>
19 #include <ModelAPI_AttributeRefAttr.h>
20 #include <ModelAPI_AttributeRefList.h>
21 #include <ModelAPI_AttributeDouble.h>
23 #include <SketchPlugin_Constraint.h>
25 #include <Geom_Line.hxx>
28 #include <XGUI_ViewerPrs.h>
29 #include <XGUI_Constants.h>
31 #include <SketchPlugin_Line.h>
33 #include <V3d_View.hxx>
34 #include <TopoDS_Vertex.hxx>
36 #include <BRep_Tool.hxx>
42 #include <QMouseEvent>
46 PartSet_OperationConstraint::PartSet_OperationConstraint(const QString& theId,
48 FeaturePtr theFeature)
49 : PartSet_OperationSketchBase(theId, theParent), mySketch(theFeature)
53 PartSet_OperationConstraint::~PartSet_OperationConstraint()
57 bool PartSet_OperationConstraint::isGranted(ModuleBase_IOperation* theOperation) const
59 return theOperation->getDescription()->operationId().toStdString() == PartSet_OperationSketch::Type();
62 void PartSet_OperationConstraint::init(FeaturePtr theFeature,
63 const std::list<XGUI_ViewerPrs>& /*theSelected*/,
64 const std::list<XGUI_ViewerPrs>& /*theHighlighted*/)
66 //if (!theFeature || theFeature->getKind() != SKETCH_LINE_KIND)
68 // use the last point of the previous feature as the first of the new one
69 //boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
70 //myInitPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_END));
73 FeaturePtr PartSet_OperationConstraint::sketch() const
78 void PartSet_OperationConstraint::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView,
79 const std::list<XGUI_ViewerPrs>& theSelected,
80 const std::list<XGUI_ViewerPrs>& /*theHighlighted*/)
82 if (theSelected.empty()) {
85 XGUI_ViewerPrs aPrs = theSelected.front();
86 FeaturePtr aFeature = aPrs.feature();
94 void PartSet_OperationConstraint::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
98 void PartSet_OperationConstraint::startOperation()
100 PartSet_OperationSketchBase::startOperation();
101 //setPointSelectionMode(!myInitPoint ? SM_FirstPoint : SM_SecondPoint);
103 emit multiSelectionEnabled(false);
106 void PartSet_OperationConstraint::abortOperation()
108 emit featureConstructed(feature(), FM_Hide);
109 PartSet_OperationSketchBase::abortOperation();
112 void PartSet_OperationConstraint::stopOperation()
114 PartSet_OperationSketchBase::stopOperation();
115 emit multiSelectionEnabled(true);
118 void PartSet_OperationConstraint::afterCommitOperation()
120 PartSet_OperationSketchBase::afterCommitOperation();
121 emit featureConstructed(feature(), FM_Deactivation);
124 FeaturePtr PartSet_OperationConstraint::createFeature(const bool theFlushMessage)
126 FeaturePtr aNewFeature = ModuleBase_Operation::createFeature(false);
128 boost::shared_ptr<SketchPlugin_Feature> aFeature =
129 boost::dynamic_pointer_cast<SketchPlugin_Feature>(sketch());
131 aFeature->addSub(aNewFeature);
134 setLinePoint(aNewFeature, myInitPoint->x(), myInitPoint->y(), LINE_ATTR_START);
135 setLinePoint(aNewFeature, myInitPoint->x(), myInitPoint->y(), LINE_ATTR_END);
137 boost::shared_ptr<ModelAPI_Data> aData = aNewFeature->data();
138 boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
139 (aData->attribute(LINE_ATTR_START));
140 PartSet_Tools::createConstraint(myInitPoint, aPoint);
143 emit featureConstructed(aNewFeature, FM_Activation);
149 void PartSet_OperationConstraint::setFeature(FeaturePtr theFeature)
151 if (!theFeature || theFeature->getKind() != SKETCH_LINE_KIND)
154 boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
156 boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr =
157 boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_A));
158 anAttr->setFeature(theFeature);
161 void PartSet_OperationConstraint::setValue(const double theValue)
163 boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
165 boost::shared_ptr<ModelAPI_AttributeDouble> anAttr =
166 boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_VALUE));
167 anAttr->setValue(theValue);