+}
+
+bool PartSet_WidgetSketchCreator::isSelectionMode() const
+{
+ AttributeSelectionListPtr anAttrList = myFeature->data()->selectionList(myAttributeListID);
+ bool aHasValueInList = anAttrList.get() && anAttrList->size() > 0;
+
+ return !aHasValueInList;
+}
+
+bool PartSet_WidgetSketchCreator::hasSubObjects() const
+{
+ bool aHasSubObjects = false;
+ CompositeFeaturePtr aComposite = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
+ if (aComposite.get())
+ aHasSubObjects = aComposite->numberOfSubs() > 0;
+ return aHasSubObjects;
+}
+
+bool PartSet_WidgetSketchCreator::setSelection(QList<ModuleBase_ViewerPrsPtr>& theValues,
+ const bool theToValidate)
+{
+ bool aDone = false;
+ if (!startSketchOperation(theValues)) {
+ myIsCustomAttribute = true;
+ QList<ModuleBase_ViewerPrsPtr>::const_iterator
+ anIt = theValues.begin(), aLast = theValues.end();
+ bool aProcessed = false;
+ for (; anIt != aLast; anIt++) {
+ ModuleBase_ViewerPrsPtr aValue = *anIt;
+ if (!theToValidate || isValidInFilters(aValue))
+ aProcessed = setSelectionCustom(aValue) || aProcessed;
+ }
+ myIsCustomAttribute = false;
+ aDone = aProcessed;
+ if (aProcessed) {
+ emit valuesChanged();
+ updateObject(myFeature);
+ setVisibleSelectionControl(false);
+ // manually deactivation because the widget was
+ // not activated as has no focus acceptin controls
+ deactivate();
+ emit focusOutWidget(this);
+ }
+ }
+ return aDone;
+}
+
+//********************************************************************
+bool PartSet_WidgetSketchCreator::processSelection()
+{
+ QList<ModuleBase_ViewerPrsPtr> aSelected = getFilteredSelected();
+ bool isDone = setSelection(aSelected, true/*false*/);
+
+ return isDone;
+}
+
+//********************************************************************
+void PartSet_WidgetSketchCreator::updateOnSelectionChanged(const bool theDone)
+{
+}
+
+bool PartSet_WidgetSketchCreator::startSketchOperation(
+ const QList<ModuleBase_ViewerPrsPtr>& theValues)
+{
+ bool aSketchStarted = false;
+
+ if (theValues.size() != 1)
+ return aSketchStarted;
+
+ ModuleBase_ViewerPrsPtr aValue = theValues.front();
+ if (!aValue.get() || !PartSet_WidgetSketchLabel::canFillSketch(aValue))
+ return aSketchStarted;
+
+ ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aValue->object());
+ /// sketch should not started by object(face) selected as global. If Local face is selected,
+ /// sketch is started
+ if (aResult.get() && aValue->shape().get() && aResult->shape()->isEqual(aValue->shape())) {
+ ResultConstructionPtr aConstruction =
+ std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aResult);
+ if (!aConstruction.get() || !aConstruction->isInfinite())
+ return aSketchStarted;
+ }
+ aSketchStarted = true;
+ // Set View size if a plane is selected
+ if (myPreviewPlanes->isPreviewDisplayed() &&
+ myPreviewPlanes->isPreviewShape(aValue->shape())) {
+ // set default plane size
+ bool isSetSizeOfView = false;
+ double aSizeOfView = 0;
+ QString aSizeOfViewStr = mySizeOfView->text();
+ if (!aSizeOfViewStr.isEmpty()) {
+ aSizeOfView = aSizeOfViewStr.toDouble(&isSetSizeOfView);
+ if (isSetSizeOfView && aSizeOfView <= 0) {
+ isSetSizeOfView = false;
+ }
+ }
+ if (isSetSizeOfView)
+ myModule->sketchMgr()->previewSketchPlane()->setSizeOfView(aSizeOfView, true);
+ }
+ // manually deactivation because the widget was not activated as has no focus acceptin controls
+ deactivate();
+ myPreviewPlanes->erasePreviewPlanes(myWorkshop);
+
+ // start edit operation for the sketch
+ ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
+ (myModule->createOperation("Sketch"));
+ QList<ModuleBase_ViewerPrsPtr> aValues;
+ aValues.push_back(aValue);
+ aFOperation->setPreselection(aValues);
+
+ myWorkshop->processLaunchOperation(aFOperation);
+
+ return aSketchStarted;
+}
+
+bool PartSet_WidgetSketchCreator::focusTo()
+{
+ // this method is called only in creation mode. In Edition mode this widget is hidden
+ if (isSelectionMode() && !hasSubObjects()) {
+ setVisibleSelectionControl(true);
+ activateSelectionControl();
+ openExtrusionTransaction();
+ return true;
+ }
+ else
+ connect(myModule, SIGNAL(resumed(ModuleBase_Operation*)),
+ SLOT(onResumed(ModuleBase_Operation*)));
+
+ return true;
+}
+
+void PartSet_WidgetSketchCreator::deactivate()
+{
+ ModuleBase_WidgetSelector::deactivate();
+
+ bool aHidePreview = myPreviewPlanes->isPreviewDisplayed();
+ myPreviewPlanes->erasePreviewPlanes(myWorkshop);
+ if (aHidePreview)
+ XGUI_Tools::workshop(myWorkshop)->viewer()->update();