+ ModuleBase_Tools::setFocus(myStackWidget, "PartSet_WidgetSketchLabel::focusTo()");
+ return true;
+}
+
+void PartSet_WidgetSketchLabel::enableFocusProcessing()
+{
+ myStackWidget->installEventFilter(this);
+}
+
+void PartSet_WidgetSketchLabel::storeAttributeValue(const AttributePtr& theAttribute)
+{
+ ModuleBase_WidgetValidated::storeAttributeValue(theAttribute);
+}
+
+void PartSet_WidgetSketchLabel::restoreAttributeValue(const AttributePtr& theAttribute,
+ const bool theValid)
+{
+ ModuleBase_WidgetValidated::restoreAttributeValue(theAttribute, theValid);
+
+ // it is not necessary to save the previous plane value because the plane is chosen once
+ DataPtr aData = feature()->data();
+ AttributeSelectionPtr aSelAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
+ (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID()));
+ if (aSelAttr) {
+ ResultPtr anEmptyResult;
+ GeomShapePtr anEmptyShape;
+ aSelAttr->setValue(anEmptyResult, anEmptyShape);
+ }
+}
+
+bool PartSet_WidgetSketchLabel::setSelectionCustom(const ModuleBase_ViewerPrsPtr& thePrs)
+{
+ return fillSketchPlaneBySelection(feature(), thePrs);
+}
+
+bool PartSet_WidgetSketchLabel::canFillSketch(const ModuleBase_ViewerPrsPtr& thePrs)
+{
+ bool aCanFillSketch = true;
+ // avoid any selection on sketch object
+ ObjectPtr anObject = thePrs->object();
+ ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
+ if (aResult.get()) {
+ FeaturePtr aFeature = ModelAPI_Feature::feature(aResult);
+ if (aFeature->getKind() == SketchPlugin_Sketch::ID())
+ aCanFillSketch = false;
+ }
+ // check plane or planar face of any non-sketch object
+ if (aCanFillSketch) {
+ std::shared_ptr<GeomAPI_Face> aGeomFace;
+
+ GeomShapePtr aGeomShape = thePrs->shape();
+ if ((!aGeomShape.get() || aGeomShape->isNull()) && aResult.get()) {
+ aGeomShape = aResult->shape();
+ }
+
+ if (aGeomShape.get() && aGeomShape->shapeType() == GeomAPI_Shape::FACE) {
+ std::shared_ptr<GeomAPI_Face> aGeomFace(new GeomAPI_Face(aGeomShape));
+ aCanFillSketch = aGeomFace.get() && aGeomFace->isPlanar();
+ }
+ else
+ aCanFillSketch = false;
+ }
+ return aCanFillSketch;
+}
+
+bool PartSet_WidgetSketchLabel::fillSketchPlaneBySelection(const FeaturePtr& theFeature,
+ const ModuleBase_ViewerPrsPtr& thePrs)
+{
+ bool isOwnerSet = false;
+
+ const GeomShapePtr& aShape = thePrs->shape();
+ std::shared_ptr<GeomAPI_Dir> aDir;
+
+ if (thePrs->object() && (theFeature != thePrs->object())) {
+ DataPtr aData = theFeature->data();
+ AttributeSelectionPtr aSelAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
+ (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID()));
+ if (aSelAttr) {
+ ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(thePrs->object());
+ if (aRes) {
+ GeomShapePtr aShapePtr(new GeomAPI_Shape());
+ if (!aShape.get() || aShape->isNull()) { // selection happens in the OCC viewer
+ aShapePtr = ModelAPI_Tools::shape(aRes);
+ }
+ else { // selection happens in OB browser
+ aShapePtr = aShape;
+ }
+ if (aShapePtr.get() != NULL) {
+ aSelAttr->setValue(aRes, aShapePtr);
+ isOwnerSet = true;
+ }
+ }
+ }
+ }
+ else if (aShape.get() && !aShape->isNull()) {
+ const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
+ aDir = setSketchPlane(theFeature, aTDShape);
+ isOwnerSet = aDir.get();
+ }
+ return isOwnerSet;
+}
+
+void PartSet_WidgetSketchLabel::activateCustom()
+{
+ std::shared_ptr<GeomAPI_Pln> aPlane = plane();
+ if (aPlane.get()) {
+ myStackWidget->setCurrentIndex(1);
+ activateSelection(true);
+ return;
+ }
+
+ myStackWidget->setCurrentIndex(0);
+ bool aBodyIsVisualized = myPreviewPlanes->hasVisualizedBodies(myWorkshop);
+
+ // Clear previous selection mode It is necessary for correct activation of preview planes
+ XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
+ XGUI_Displayer* aDisp = aWorkshop->displayer();
+ aDisp->activateObjects(QIntList(), aDisp->displayedObjects(), false);
+
+ if (!aBodyIsVisualized) {
+ // We have to select a plane before any operation
+ myPreviewPlanes->showPreviewPlanes(myWorkshop);
+ }
+ activateSelection(true);
+
+ //myLabel->setText(myText);
+ //myLabel->setToolTip(myTooltip);
+
+ connect(XGUI_Tools::workshop(myWorkshop)->selector(), SIGNAL(selectionChanged()),
+ this, SLOT(onSelectionChanged()));
+ activateFilters(true);
+}
+
+void PartSet_WidgetSketchLabel::deactivate()
+{
+ ModuleBase_ModelWidget::deactivate();
+ bool aHidePreview = myPreviewPlanes->isPreviewDisplayed();
+ myPreviewPlanes->erasePreviewPlanes(myWorkshop);
+ activateSelection(false);
+
+ activateFilters(false);
+ if (aHidePreview)
+ myWorkshop->viewer()->update();
+}
+
+void PartSet_WidgetSketchLabel::activateSelection(bool toActivate)
+{
+ if (toActivate) {
+ QIntList aModes;
+ std::shared_ptr<GeomAPI_Pln> aPlane = plane();
+ if (aPlane.get()) {
+ myWorkshop->module()->activeSelectionModes(aModes);
+ }
+ else {
+ aModes << TopAbs_FACE;
+ }
+ myWorkshop->activateSubShapesSelection(aModes);