+std::list<int> PartSet_OperationSketch::getSelectionModes(ObjectPtr theFeature) const
+{
+ std::list<int> aModes;
+ if (!hasSketchPlane())
+ aModes.push_back(TopAbs_FACE);
+ else
+ aModes = PartSet_OperationSketchBase::getSelectionModes(theFeature);
+
+ return aModes;
+}
+
+/// Initializes the operation with previously created feature. It is used in sequental operations
+void PartSet_OperationSketch::initFeature(FeaturePtr theFeature)
+{
+ if (theFeature)
+ setEditingFeature(theFeature);
+}
+
+FeaturePtr PartSet_OperationSketch::sketch() const
+{
+ return feature();
+}
+
+void PartSet_OperationSketch::mousePressed(QMouseEvent* theEvent, Handle_V3d_View theView,
+ const std::list<ModuleBase_ViewerPrs>& theSelected,
+ const std::list<ModuleBase_ViewerPrs>& theHighlighted)
+{
+ if (hasSketchPlane()) {
+ // if shift button is pressed and there are some already selected objects, the operation should
+ // not be started. We just want to combine some selected objects.
+ bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
+ if (aHasShift && theSelected.size() > 0)
+ return;
+
+ if (theHighlighted.size() == 1) {
+ ObjectPtr aFeature = theHighlighted.front().object();
+ if (aFeature) {
+ std::string anOperationType =
+ (theSelected.size() > 1) ?
+ PartSet_OperationFeatureEditMulti::Type() : PartSet_OperationFeatureEdit::Type();
+ restartOperation(anOperationType, aFeature);
+ }
+ } else
+ myFeatures = theHighlighted;
+
+ } else {
+ if (!theHighlighted.empty()) {
+ ModuleBase_ViewerPrs aPrs = theHighlighted.front();
+ const TopoDS_Shape& aShape = aPrs.shape();
+ if (!aShape.IsNull())
+ setSketchPlane(aShape);
+ }
+ }
+}
+
+void PartSet_OperationSketch::mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
+ const std::list<ModuleBase_ViewerPrs>& theSelected,
+ const std::list<ModuleBase_ViewerPrs>& theHighlighted)
+{
+ if (hasSketchPlane()) {
+ /// TODO: OCC bug: 25034 - the highlighted list should be filled not only for AIS_Shape
+ /// but for other IO, for example constraint dimensions.
+ /// It is empty and we have to use the process mouse release to start edition operation
+ /// for these objects
+ if (theSelected.size() == 1) {
+ ObjectPtr aObject = theSelected.front().object();
+ if (aObject) {
+ restartOperation(PartSet_OperationFeatureEdit::Type(), aObject);
+ }
+ }
+ }
+}
+
+void PartSet_OperationSketch::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
+{
+ if (!hasSketchPlane() || !(theEvent->buttons() & Qt::LeftButton) || myFeatures.empty())
+ return;
+
+ if (myFeatures.size() != 1) {
+ FeaturePtr aFeature = PartSet_Tools::nearestFeature(theEvent->pos(), theView, feature(),
+ myFeatures);
+ if (aFeature)
+ restartOperation(PartSet_OperationFeatureEditMulti::Type(), aFeature);
+ }
+}
+
+std::list<FeaturePtr> PartSet_OperationSketch::subFeatures() const
+{
+ std::list<FeaturePtr> aFeaList;
+ FeaturePtr aFeature = feature();
+ if (!aFeature)
+ return aFeaList;
+
+ boost::shared_ptr<ModelAPI_Data> aData = aFeature->data();
+ if (!aData->isValid())
+ return std::list<FeaturePtr>();
+ boost::shared_ptr<ModelAPI_AttributeRefList> aRefList = boost::dynamic_pointer_cast<
+ ModelAPI_AttributeRefList>(aData->attribute(SketchPlugin_Sketch::FEATURES_ID()));
+
+ std::list<ObjectPtr> aList = aRefList->list();
+ std::list<ObjectPtr>::iterator aIt;
+ for (aIt = aList.begin(); aIt != aList.end(); ++aIt) {
+ FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(*aIt);
+ if (aFeature)
+ aFeaList.push_back(aFeature);
+ }
+ return aFeaList;
+}
+
+void PartSet_OperationSketch::stopOperation()
+{
+ PartSet_OperationSketchBase::stopOperation();
+ emit featureConstructed(feature(), FM_Hide);
+ emit closeLocalContext();
+
+ FeaturePtr aFeature = feature();
+ std::list<ResultPtr> aResults = aFeature->results();
+ std::list<ResultPtr>::const_iterator aIt;
+ for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) {
+ ModelAPI_EventCreator::get()->sendUpdated(
+ *aIt, Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY));
+ }
+ //ModelAPI_EventCreator::get()->sendUpdated(aFeature,
+ // Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY));
+}
+
+bool PartSet_OperationSketch::isNestedOperationsEnabled() const
+{
+ return hasSketchPlane();
+}
+
+void PartSet_OperationSketch::startOperation()
+{
+ PartSet_OperationSketchBase::startOperation();
+ if (!isEditOperation())
+ emit fitAllView();
+}
+
+bool PartSet_OperationSketch::hasSketchPlane() const
+{
+ bool aHasPlane = false;
+
+ if (feature()) {
+ boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
+ AttributeDoublePtr anAttr;
+ boost::shared_ptr<GeomDataAPI_Dir> aNormal = boost::dynamic_pointer_cast<GeomDataAPI_Dir>(
+ aData->attribute(SketchPlugin_Sketch::NORM_ID()));
+ aHasPlane = aNormal && !(aNormal->x() == 0 && aNormal->y() == 0 && aNormal->z() == 0);
+ }
+ return aHasPlane;
+}
+
+void PartSet_OperationSketch::setSketchPlane(const TopoDS_Shape& theShape)