X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPartSet%2FPartSet_WidgetSketchCreator.cpp;h=7f9fc5adae6c9a4a3725f0d91e36e1138b66b86a;hb=384c819a1edf4b726e3a523c1ffd2b5e6b16a4c0;hp=26b7481578766d01e4be63443dd54d0b11df5d99;hpb=dd31f5aedab7f3bb833b97fae5f82b32a92f927c;p=modules%2Fshaper.git diff --git a/src/PartSet/PartSet_WidgetSketchCreator.cpp b/src/PartSet/PartSet_WidgetSketchCreator.cpp index 26b748157..7f9fc5ada 100644 --- a/src/PartSet/PartSet_WidgetSketchCreator.cpp +++ b/src/PartSet/PartSet_WidgetSketchCreator.cpp @@ -1,8 +1,22 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -// File: PartSet_WidgetSketchCreator.cpp -// Created: 08 June 2015 -// Author: Vitaly SMETANNIKOV +// Copyright (C) 2014-2017 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or +// email : webmaster.salome@opencascade.com +// #include "PartSet_WidgetSketchCreator.h" #include "PartSet_Module.h" @@ -22,6 +36,8 @@ #include +#include + #include #include #include @@ -37,18 +53,23 @@ #include #include #include +#include + #include #include #include #include +#include //#include #include #include #include -PartSet_WidgetSketchCreator::PartSet_WidgetSketchCreator(QWidget* theParent, +#define DEBUG_UNDO_INVALID_SKETCH + +PartSet_WidgetSketchCreator::PartSet_WidgetSketchCreator(QWidget* theParent, PartSet_Module* theModule, const Config_WidgetAPI* theData) : ModuleBase_WidgetSelector(theParent, theModule->workshop(), theData), @@ -65,22 +86,24 @@ PartSet_WidgetSketchCreator::PartSet_WidgetSketchCreator(QWidget* theParent, QString aLabelText = QString::fromStdString(theData->widgetLabel()); QString aLabelIcon = QString::fromStdString(theData->widgetIcon()); - myLabel = new QLabel(aLabelText, this); - myLabel->setWordWrap(true); - aLayout->addWidget(myLabel); - /*if (!aLabelIcon.isEmpty()) - myLabel->setPixmap(QPixmap(aLabelIcon)); + // Size of the View control + mySizeOfViewWidget = new QWidget(this); + QHBoxLayout* aSizeLayout = new QHBoxLayout(mySizeOfViewWidget); + aSizeLayout->addWidget(new QLabel("Size of the view", mySizeOfViewWidget)); + mySizeOfView = new QLineEdit(mySizeOfViewWidget); + QDoubleValidator* aValidator = new QDoubleValidator(0, DBL_MAX, 12, mySizeOfView); + aValidator->setLocale(ModuleBase_Tools::doubleLocale()); + aValidator->setNotation(QDoubleValidator::StandardNotation); + mySizeOfView->setValidator(aValidator); + aSizeLayout->addWidget(mySizeOfView); - QString aToolTip = QString::fromStdString(theData->widgetTooltip()); - myTextLine = new QLineEdit(this); - myTextLine->setReadOnly(true); - myTextLine->setToolTip(aToolTip); - myTextLine->installEventFilter(this); - - myLabel->setToolTip(aToolTip); + myLabel = new QLabel(aLabelText, this); + myLabel->setWordWrap(true); - aLayout->addRow(myLabel, myTextLine);*/ + aLayout->addWidget(mySizeOfViewWidget); + aLayout->addWidget(myLabel); + aLayout->addStretch(1); std::string aTypes = theData->getProperty("shape_types"); myShapeTypes = QString(aTypes.c_str()).split(' ', QString::SkipEmptyParts); @@ -90,6 +113,9 @@ PartSet_WidgetSketchCreator::PartSet_WidgetSketchCreator(QWidget* theParent, PartSet_WidgetSketchCreator::~PartSet_WidgetSketchCreator() { + // we need to deactivate here in order to hide preview planes if the selection mode is + // active + deactivate(); } QList PartSet_WidgetSketchCreator::getControls() const @@ -101,16 +127,10 @@ QList PartSet_WidgetSketchCreator::getControls() const bool PartSet_WidgetSketchCreator::restoreValueCustom() { - /*CompositeFeaturePtr aCompFeature = - std::dynamic_pointer_cast(myFeature); - if (aCompFeature->numberOfSubs() > 0) { - FeaturePtr aSubFeature = aCompFeature->subFeature(0); - myTextLine->setText(QString::fromStdString(aSubFeature->data()->name())); - }*/ return true; } -bool PartSet_WidgetSketchCreator::storeValueCustom() const +bool PartSet_WidgetSketchCreator::storeValueCustom() { return true; } @@ -127,7 +147,7 @@ AttributePtr PartSet_WidgetSketchCreator::attribute() const } //******************************************************************** -void PartSet_WidgetSketchCreator::openTransaction() +void PartSet_WidgetSketchCreator::openExtrusionTransaction() { SessionPtr aMgr = ModelAPI_Session::get(); bool aIsOp = aMgr->isOperation(); @@ -138,7 +158,7 @@ void PartSet_WidgetSketchCreator::openTransaction() } //******************************************************************** -bool PartSet_WidgetSketchCreator::isValidSelection(const ModuleBase_ViewerPrs& theValue) +bool PartSet_WidgetSketchCreator::isValidSelection(const ModuleBase_ViewerPrsPtr& theValue) { bool aValid = false; if (myIsCustomAttribute) { @@ -168,14 +188,16 @@ bool PartSet_WidgetSketchCreator::isValidSelection(const ModuleBase_ViewerPrs& t } //******************************************************************** -bool PartSet_WidgetSketchCreator::isValidSelectionCustom(const ModuleBase_ViewerPrs& theValue) +bool PartSet_WidgetSketchCreator::isValidSelectionCustom(const ModuleBase_ViewerPrsPtr& theValue) { return PartSet_WidgetSketchLabel::canFillSketch(theValue); } void PartSet_WidgetSketchCreator::activateSelectionControl() { - setVisibleSelectionControl(true); + // reset previously set size of view needed on restart extrusion after Sketch + if (myModule->sketchMgr()->previewSketchPlane()->isUseSizeOfView()) + myModule->sketchMgr()->previewSketchPlane()->setSizeOfView(0, false); // we need to call activate here as the widget has no focus accepted controls // if these controls are added here, activate will happens automatically after focusIn() @@ -198,17 +220,26 @@ void PartSet_WidgetSketchCreator::setVisibleSelectionControl(const bool theSelec else { // hide current control if (aWidget == this) aWidget->setVisible(false); - else + else { aWidget->setVisible(true); + if (aWidget->attributeID() == myAttributeListID) + setEnabledModelWidget(aWidget, !hasSubObjects()); + } } } if (theSelectionControl) { bool aBodyIsVisualized = myPreviewPlanes->hasVisualizedBodies(myWorkshop); - if (!aBodyIsVisualized) { + bool aSketchIsVisualized = myPreviewPlanes->hasVisualizedSketch(myWorkshop); + if (!aBodyIsVisualized && !aSketchIsVisualized) { // We have to select a plane before any operation myPreviewPlanes->showPreviewPlanes(myWorkshop); + mySizeOfViewWidget->setVisible(true); } + else { + mySizeOfViewWidget->setVisible(false); + } + } else { bool aHidePreview = myPreviewPlanes->isPreviewDisplayed(); myPreviewPlanes->erasePreviewPlanes(myWorkshop); @@ -217,7 +248,7 @@ void PartSet_WidgetSketchCreator::setVisibleSelectionControl(const bool theSelec } } -QIntList PartSet_WidgetSketchCreator::getShapeTypes() const +QIntList PartSet_WidgetSketchCreator::shapeTypes() const { QIntList aShapeTypes; foreach(QString aType, myShapeTypes) { @@ -229,97 +260,21 @@ QIntList PartSet_WidgetSketchCreator::getShapeTypes() const void PartSet_WidgetSketchCreator::setEditingMode(bool isEditing) { ModuleBase_ModelWidget::setEditingMode(isEditing); - if (isEditing) + if (isEditing) { setVisibleSelectionControl(false); -} - -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(anOperation); - FeaturePtr aCurrentFeature = aFOperation ? aFOperation->feature() : FeaturePtr(); - - ModuleBase_Operation* aPOperation = anOpMgr->previousOperation(anOperation); - ModuleBase_OperationFeature* aFPOperation = dynamic_cast(aPOperation); - FeaturePtr aParentFeature = aFPOperation ? aFPOperation->feature() : FeaturePtr(); - - CompositeFeaturePtr aCompositeFeature = - std::dynamic_pointer_cast(aCurrentFeature); - CompositeFeaturePtr aPCompositeFeature = - std::dynamic_pointer_cast(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(); - - std::list aSelListAttributes = aParentFeature->data()->attributes( - ModelAPI_AttributeSelectionList::typeId()); - if (aSelListAttributes.size() == 1) { - AttributePtr aFirstAttribute = aSelListAttributes.front(); - /// Sub-feature of the composite should be set in the base list. - setSketchObjectToList(aPCompositeFeature, aFirstAttribute); - 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(); + ModuleBase_ModelWidget* anAttributeListWidget = 0; + XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myModule->workshop()); + XGUI_PropertyPanel* aPanel = aWorkshop->propertyPanel(); + const QList& aWidgets = aPanel->modelWidgets(); + foreach(ModuleBase_ModelWidget* aWidget, aWidgets) { + if (aWidget->attributeID() == myAttributeListID) { + anAttributeListWidget = aWidget; + break; } } - } - return aCanCommit; -} - -void PartSet_WidgetSketchCreator::setSketchObjectToList(const CompositeFeaturePtr& theCompositeFeature, - const AttributePtr& theAttribute) -{ - if (!theCompositeFeature.get() || theCompositeFeature->numberOfSubs() != 1) - return; - - AttributeSelectionListPtr aBaseObjectsSelectionList = - std::dynamic_pointer_cast(theAttribute); - if(!aBaseObjectsSelectionList.get() || aBaseObjectsSelectionList->isInitialized()) { - return; - } - - FeaturePtr aSketchFeature = theCompositeFeature->subFeature(0); - if(!aSketchFeature.get() || aSketchFeature->results().empty()) { - return; - } - - ResultPtr aSketchRes = aSketchFeature->results().front(); - ResultConstructionPtr aConstruction = std::dynamic_pointer_cast(aSketchRes); - if(!aConstruction.get()) { - return; - } - - if(aBaseObjectsSelectionList->size() == 0) { - aBaseObjectsSelectionList->append(aSketchRes, GeomShapePtr()); + if (anAttributeListWidget) + setEnabledModelWidget(anAttributeListWidget, !hasSubObjects()); } } @@ -331,16 +286,28 @@ bool PartSet_WidgetSketchCreator::isSelectionMode() const return !aHasValueInList; } -bool PartSet_WidgetSketchCreator::setSelection(QList& theValues, +bool PartSet_WidgetSketchCreator::hasSubObjects() const +{ + bool aHasSubObjects = false; + + bool aCanSetFocus = true; + CompositeFeaturePtr aComposite = std::dynamic_pointer_cast(myFeature); + if (aComposite.get()) + aHasSubObjects = aComposite->numberOfSubs() > 0; + return aHasSubObjects; +} + +bool PartSet_WidgetSketchCreator::setSelection(QList& theValues, const bool theToValidate) { bool aDone = false; if (!startSketchOperation(theValues)) { myIsCustomAttribute = true; - QList::const_iterator anIt = theValues.begin(), aLast = theValues.end(); + QList::const_iterator + anIt = theValues.begin(), aLast = theValues.end(); bool aProcessed = false; for (; anIt != aLast; anIt++) { - ModuleBase_ViewerPrs aValue = *anIt; + ModuleBase_ViewerPrsPtr aValue = *anIt; if (!theToValidate || isValidInFilters(aValue)) aProcessed = setSelectionCustom(aValue) || aProcessed; } @@ -350,7 +317,8 @@ bool PartSet_WidgetSketchCreator::setSelection(QList& theV emit valuesChanged(); updateObject(myFeature); setVisibleSelectionControl(false); - // manually deactivation because the widget was not activated as has no focus acceptin controls + // manually deactivation because the widget was + // not activated as has no focus acceptin controls deactivate(); emit focusOutWidget(this); } @@ -359,10 +327,12 @@ bool PartSet_WidgetSketchCreator::setSelection(QList& theV } //******************************************************************** -void PartSet_WidgetSketchCreator::onSelectionChanged() +bool PartSet_WidgetSketchCreator::processSelection() { - QList aSelected = getFilteredSelected(); + QList aSelected = getFilteredSelected(); bool isDone = setSelection(aSelected, true/*false*/); + + return isDone; } //******************************************************************** @@ -370,65 +340,79 @@ void PartSet_WidgetSketchCreator::updateOnSelectionChanged(const bool theDone) { } -bool PartSet_WidgetSketchCreator::startSketchOperation(const QList& theValues) +bool PartSet_WidgetSketchCreator::startSketchOperation( + const QList& theValues) { bool aSketchStarted = false; if (theValues.size() != 1) return aSketchStarted; - ModuleBase_ViewerPrs aValue = theValues.front(); - if (!PartSet_WidgetSketchLabel::canFillSketch(aValue)) + ModuleBase_ViewerPrsPtr aValue = theValues.front(); + if (!aValue.get() || !PartSet_WidgetSketchLabel::canFillSketch(aValue)) return aSketchStarted; + ResultPtr aResult = std::dynamic_pointer_cast(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(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(); bool aHidePreview = myPreviewPlanes->isPreviewDisplayed(); myPreviewPlanes->erasePreviewPlanes(myWorkshop); // Launch Sketch operation - CompositeFeaturePtr aCompFeature = + CompositeFeaturePtr aCompFeature = std::dynamic_pointer_cast(myFeature); - /// add sketch feature without current feature change. - /// it is important to do not change the current feature in order to - /// after sketch edition, the extrusion cut feature becomes current - SessionPtr aMgr = ModelAPI_Session::get(); - DocumentPtr aDoc = aMgr->activeDocument(); - FeaturePtr aPreviousCurrentFeature = aDoc->currentFeature(false); - FeaturePtr aSketch = aCompFeature->addFeature("Sketch"); - - PartSet_WidgetSketchLabel::fillSketchPlaneBySelection(aSketch, aValue); - - aDoc->setCurrentFeature(aPreviousCurrentFeature, false); - // start edit operation for the sketch ModuleBase_OperationFeature* aFOperation = dynamic_cast (myModule->createOperation("Sketch")); - if (aFOperation) - aFOperation->setFeature(aSketch); - myModule->sendOperation(aFOperation); + QList aValues; + aValues.push_back(aValue); + aFOperation->setPreselection(aValues); + + myWorkshop->processLaunchOperation(aFOperation); return aSketchStarted; } bool PartSet_WidgetSketchCreator::focusTo() { - if (isSelectionMode()) { + // this method is called only in creation mode. In Edition mode this widget is hidden + if (isSelectionMode() && !hasSubObjects()) { + setVisibleSelectionControl(true); activateSelectionControl(); - // Open transaction that is general for the previous nested one: it will be closed on nested commit - openTransaction(); + openExtrusionTransaction(); return true; } - else { - connect(myModule, SIGNAL(resumed(ModuleBase_Operation*)), SLOT(onResumed(ModuleBase_Operation*))); - // Open transaction that is general for the previous nested one: it will be closed on nested commit - openTransaction(); - restoreValue(); - } - return false; + else + connect(myModule, SIGNAL(resumed(ModuleBase_Operation*)), + SLOT(onResumed(ModuleBase_Operation*))); + + return true; } void PartSet_WidgetSketchCreator::deactivate() @@ -444,80 +428,169 @@ void PartSet_WidgetSketchCreator::deactivate() void PartSet_WidgetSketchCreator::onResumed(ModuleBase_Operation* theOp) { - XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myModule->workshop()); + SessionPtr aMgr = ModelAPI_Session::get(); + bool aIsOp = aMgr->isOperation(); + if (aIsOp) { + // in current implementation, all transactions are closed when resume happens + // so, this is a wrong case, which is not checked. + // To provide it, make correction in later rows about abort/undo transactions + return; + } + // Set visible only selection control + setVisibleSelectionControl(true); - CompositeFeaturePtr aCompFeature = + // Validate the created sketch. If it is valid, it is set into the composite feature selection + // list, otherwise it is removed + CompositeFeaturePtr aCompFeature = std::dynamic_pointer_cast(myFeature); - //CompositeFeaturePtr aSketchFeature = - // std::dynamic_pointer_cast(aCompFeature->subFeature(0)); - if (aCompFeature->numberOfSubs() == 0) { - // do nothing, selection control should be hidden - setVisibleSelectionControl(false); - } else { - // check if the created sketch is invalid. Validate attribute selection list - // Shetch should be deleted if the attribute is invalid. - AttributeSelectionListPtr anAttrList = myFeature->data()->selectionList(myAttributeListID); - + AttributeSelectionListPtr anAttrList = myFeature->data()->selectionList(myAttributeListID); + if (aCompFeature->numberOfSubs() > 0) { + // set the sub feature to attribute selection list and check whether sketch is valid SessionPtr aMgr = ModelAPI_Session::get(); - ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); - std::string aValidatorID, anError; - bool isValidPComposite = aFactory->validate(anAttrList, aValidatorID, anError); - /// if the sketch is not appropriate fro extrusion, it should be deleted and - /// the selection control should be activated again - if (!isValidPComposite) { - CompositeFeaturePtr aSketchFeature = - std::dynamic_pointer_cast(aCompFeature->subFeature(0)); - + const static std::string aNestedOpID("Set Sketch result into Selection list"); + aMgr->startOperation(aNestedOpID, false); // false to not attach to Extrusion operation + setSketchObjectToList(aCompFeature, anAttrList); + aMgr->finishOperation(); + + if (!validateSelectionList()) { +#ifdef DEBUG_UNDO_INVALID_SKETCH + aMgr->undo(); // Extrusion modification parameters: setSketchObjectToList() + aMgr->undo(); /// Sketch creation +#else + aMgr->startOperation("Delete invalid Sketch feature", false); + + // delete invalid sketch + CompositeFeaturePtr aSketchFeature = + std::dynamic_pointer_cast(aCompFeature->subFeature(0)); QObjectPtrList anObjects; anObjects.append(aSketchFeature); - std::set anIgnoredFeatures; - aWorkshop->deleteFeatures(anObjects, anIgnoredFeatures); - // do nothing, selection control should be shown - activateSelectionControl(); + XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myModule->workshop()); + aWorkshop->deleteFeatures(anObjects); + + aMgr->finishOperation(); +#endif } - else { - setVisibleSelectionControl(false); - // Update value in attribute selection list - XGUI_PropertyPanel* aPanel = aWorkshop->propertyPanel(); - const QList& aWidgets = aPanel->modelWidgets(); - foreach(ModuleBase_ModelWidget* aWidget, aWidgets) { - if (aWidget->attributeID() == myAttributeListID) - aWidget->restoreValue(); - } + } + openExtrusionTransaction(); - // Hide sketcher result - CompositeFeaturePtr aSketchFeature = - std::dynamic_pointer_cast(aCompFeature->subFeature(0)); - std::list aResults = aSketchFeature->results(); - std::list::const_iterator aIt; - for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) { - (*aIt)->setDisplayed(false); + if (aCompFeature->numberOfSubs() == 0) { + // call activateWidget() of the parent to connect to the viewer seleciton + activateSelectionControl(); + } + else { + // check if the created sketch is valid. If it is invalid, it will be deleted with warning else + /// the attribute selection list will be filled by result of this sketch. + setVisibleSelectionControl(false); + + // Update value in attribute selection list + XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myModule->workshop()); + XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel(); + const QList& aWidgets = aPropertyPanel->modelWidgets(); + ModuleBase_ModelWidget* aListWidget = 0; + foreach(ModuleBase_ModelWidget* aWidget, aWidgets) { + if (aWidget->attributeID() == myAttributeListID) { + aListWidget = aWidget; + break; } - aSketchFeature->setDisplayed(false); - static Events_Loop* aLoop = Events_Loop::loop(); - aLoop->flush(aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY)); - - // Add Selected body were created the sketcher to list of selected objects - std::string anObjectsAttribute = FeaturesPlugin_CompositeBoolean::OBJECTS_ID(); - AttributeSelectionListPtr aSelList = aCompFeature->data()->selectionList(anObjectsAttribute); - if (aSelList.get()) { - DataPtr aData = aSketchFeature->data(); - AttributeSelectionPtr aSelAttr = std::dynamic_pointer_cast - (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID())); - ResultPtr aRes = aSelAttr.get() ? aSelAttr->context() : ResultPtr(); - if (aRes.get()) { - SessionPtr aMgr = ModelAPI_Session::get(); - ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); - AttributePtr anAttribute = myFeature->attribute(anObjectsAttribute); - std::string aValidatorID, anError; - aSelList->append(aRes, GeomShapePtr()); - if (aFactory->validate(anAttribute, aValidatorID, anError)) - updateObject(aCompFeature); - else - aSelList->clear(); - } + } + if (aListWidget) { + aListWidget->restoreValue(); + aPropertyPanel->activateNextWidget(aListWidget); + } + + // Hide sketcher result + CompositeFeaturePtr aSketchFeature = + std::dynamic_pointer_cast(aCompFeature->subFeature(0)); + std::list aResults = aSketchFeature->results(); + std::list::const_iterator aIt; + for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) { + (*aIt)->setDisplayed(false); + } + aSketchFeature->setDisplayed(false); + static Events_Loop* aLoop = Events_Loop::loop(); + aLoop->flush(aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY)); + + // Add Selected body were created the sketcher to list of selected objects + std::string anObjectsAttribute = FeaturesPlugin_CompositeBoolean::OBJECTS_ID(); + AttributeSelectionListPtr aSelList = aCompFeature->data()->selectionList(anObjectsAttribute); + if (aSelList.get()) { + DataPtr aData = aSketchFeature->data(); + AttributeSelectionPtr aSelAttr = std::dynamic_pointer_cast + (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID())); + ResultPtr aRes = aSelAttr.get() ? aSelAttr->context() : ResultPtr(); + if (aRes.get()) { + SessionPtr aMgr = ModelAPI_Session::get(); + ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); + AttributePtr anAttribute = myFeature->attribute(anObjectsAttribute); + std::string aValidatorID; + Events_InfoMessage anError; + aSelList->append(aRes, GeomShapePtr()); + if (aFactory->validate(anAttribute, aValidatorID, anError)) + updateObject(aCompFeature); + else + aSelList->clear(); } } } + restoreValue(); +} + +bool PartSet_WidgetSketchCreator::validateSelectionList() const +{ + AttributeSelectionListPtr anAttrList = myFeature->data()->selectionList(myAttributeListID); + + SessionPtr aMgr = ModelAPI_Session::get(); + ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); + std::string aValidatorID; + Events_InfoMessage anError; + bool isValidPComposite = aFactory->validate(anAttrList, aValidatorID, anError); + if (!isValidPComposite) { + XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myModule->workshop()); + // TODO(spo): translate + QMessageBox::question(aWorkshop->desktop(), tr("Apply current feature"), + tr("Sketch is invalid and will be deleted.\nError: %1") + .arg(anError.messageString().c_str()), + QMessageBox::Ok); + } + return isValidPComposite; +} + +void PartSet_WidgetSketchCreator::setSketchObjectToList( + const CompositeFeaturePtr& theCompositeFeature, + const AttributePtr& theAttribute) +{ + if (!theCompositeFeature.get() || theCompositeFeature->numberOfSubs() != 1) + return; + + AttributeSelectionListPtr aBaseObjectsSelectionList = + std::dynamic_pointer_cast(theAttribute); + if(!aBaseObjectsSelectionList.get() || aBaseObjectsSelectionList->isInitialized()) { + return; + } + + FeaturePtr aSketchFeature = theCompositeFeature->subFeature(0); + if(!aSketchFeature.get() || aSketchFeature->results().empty()) { + return; + } + + ResultPtr aSketchRes = aSketchFeature->results().front(); + ResultConstructionPtr aConstruction = + std::dynamic_pointer_cast(aSketchRes); + if(!aConstruction.get()) { + return; + } + + if(aBaseObjectsSelectionList->size() == 0) { + aBaseObjectsSelectionList->append(aSketchRes, GeomShapePtr()); + } +} + +void PartSet_WidgetSketchCreator::setEnabledModelWidget(ModuleBase_ModelWidget* theModelWidget, + const bool theEnabled) +{ + QList aMyControls = theModelWidget->getControls(); + foreach(QWidget* eachControl, aMyControls) { + eachControl->setEnabled(theEnabled); + } }