-bool PartSet_WidgetSketchCreator::canCommitCurrentSketch(ModuleBase_IWorkshop* theWorkshop)
-{
- bool aCanCommit = true;
- ModuleBase_Operation* anOperation = theWorkshop->currentOperation();
- XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(theWorkshop);
- XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
- // check if the operation is nested
- if (anOperation && anOpMgr->operationsCount() > 1) {
- ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(anOperation);
- FeaturePtr aCurrentFeature = aFOperation ? aFOperation->feature() : FeaturePtr();
-
- ModuleBase_Operation* aPOperation = anOpMgr->previousOperation(anOperation);
- ModuleBase_OperationFeature* aFPOperation = dynamic_cast<ModuleBase_OperationFeature*>(aPOperation);
- FeaturePtr aParentFeature = aFPOperation ? aFPOperation->feature() : FeaturePtr();
-
- CompositeFeaturePtr aCompositeFeature =
- std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aCurrentFeature);
- CompositeFeaturePtr aPCompositeFeature =
- std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aParentFeature);
- // check if both features are composite: extrusion and sketch
- if (aCompositeFeature.get() && aPCompositeFeature.get()) {
- // selection attribute list is currently filled in execute(), so we need to call it
- // if there is no opened transaction, it should be started and finished
- SessionPtr aMgr = ModelAPI_Session::get();
- bool aIsOp = aMgr->isOperation();
- if (!aIsOp)
- aMgr->startOperation();
- aPCompositeFeature->execute(); // to fill attribute selection list
-
- std::list<AttributePtr> aSelListAttributes = aParentFeature->data()->attributes(
- ModelAPI_AttributeSelectionList::typeId());
- if (aSelListAttributes.size() == 1) {
- AttributePtr aFirstAttribute = aSelListAttributes.front();
-
- SessionPtr aMgr = ModelAPI_Session::get();
- ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
- std::string aValidatorID, anError;
- bool isValidPComposite = aFactory->validate(aFirstAttribute, aValidatorID, anError);
- if (!isValidPComposite) {
- int anAnswer = QMessageBox::question(
- aWorkshop->desktop(), tr("Apply current feature"),
- tr("The current feature can not be used as an argument of the parent feature.\n\
- After apply it will be deleted. Would you like to continue?"),
- QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Cancel);
- if (anAnswer == QMessageBox::Ok)
- aCanCommit = true;
- else
- aCanCommit = false;
- }
- }
- if (!aIsOp) {
- if (aCanCommit)
- aMgr->finishOperation();
- else
- aMgr->abortOperation();