X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModuleBase%2FModuleBase_OperationFeature.cpp;h=2508ac0c198030e91bc9ae864a2daae3f51ea2e7;hb=e32f95642855a63da2727cb324ce2a75632a712f;hp=da5ff1fcb2c3f5325ad25c0e63fbf2621719d138;hpb=42985955d89fa845790a7e38609f5b6838285147;p=modules%2Fshaper.git diff --git a/src/ModuleBase/ModuleBase_OperationFeature.cpp b/src/ModuleBase/ModuleBase_OperationFeature.cpp index da5ff1fcb..2508ac0c1 100755 --- a/src/ModuleBase/ModuleBase_OperationFeature.cpp +++ b/src/ModuleBase/ModuleBase_OperationFeature.cpp @@ -15,6 +15,7 @@ #include "ModuleBase_IPropertyPanel.h" #include "ModuleBase_ISelection.h" #include "ModuleBase_IViewer.h" +#include "ModuleBase_Tools.h" #include #include @@ -34,6 +35,13 @@ #include +// the define to check the activated object as a sub-feature by argument of +// the operation feature. E.g. rectangle feature(operation), line(in argument) to be not activated +#define DEBUG_DO_NOT_ACTIVATE_SUB_FEATURE +#ifdef DEBUG_DO_NOT_ACTIVATE_SUB_FEATURE +#include +#endif + #ifdef _DEBUG #include #endif @@ -49,11 +57,16 @@ ModuleBase_OperationFeature::~ModuleBase_OperationFeature() clearPreselection(); } -void ModuleBase_OperationFeature::setEditOperation(const bool theRestartTransaction) +void ModuleBase_OperationFeature::setEditOperation(const bool& isEditState + /*const bool theRestartTransaction*/) { - if (isEditOperation()) + bool isCurrentEditState = isEditOperation(); + if (isCurrentEditState == isEditState) return; + /* + // this case is obsolete as it was not approved for reentrant sketch operation + // it was implemented when isEditState did not exist and only edit operation can be set if (theRestartTransaction) { // finsh previous create operation emit beforeCommitted(); @@ -68,9 +81,8 @@ void ModuleBase_OperationFeature::setEditOperation(const bool theRestartTransact } ModelAPI_Session::get()->startOperation(anId.toStdString()); emit beforeStarted(); - } - else - myIsEditing = true; + } else*/ + myIsEditing = isEditState; propertyPanel()->setEditingMode(isEditOperation()); } @@ -86,17 +98,9 @@ bool ModuleBase_OperationFeature::isValid() const return true; // rename operation if (myFeature->isAction()) return true; - //Get validators for the Id - SessionPtr aMgr = ModelAPI_Session::get(); - ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); - bool aValid = aFactory->validate(myFeature); - - // the feature exec state should be checked in order to do not apply features, which result can not - // be built. E.g. extrusion on sketch, where the "to" is a perpendicular plane to the sketch - bool isDone = ( myFeature->data()->execState() == ModelAPI_StateDone - || myFeature->data()->execState() == ModelAPI_StateMustBeUpdated ); - return aValid && isDone; + std::string anError = ModelAPI_Tools::getFeatureError(myFeature); + return anError.empty(); } void ModuleBase_OperationFeature::startOperation() @@ -168,8 +172,10 @@ FeaturePtr ModuleBase_OperationFeature::createFeature(const bool theFlushMessage }*/ } - if (theFlushMessage) + if (theFlushMessage) { Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED)); + Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); + } return myFeature; } @@ -191,6 +197,29 @@ bool ModuleBase_OperationFeature::hasObject(ObjectPtr theObj) const if (theObj == (*aIt)) return true; } +#ifdef DEBUG_DO_NOT_ACTIVATE_SUB_FEATURE + if (aFeature->isMacro()) { + // macro feature may refers to sub-features, which also should be deactivated when the operation + // is active, e.g. rectangle'lines. + FeaturePtr anObjectFeature = ModelAPI_Feature::feature(theObj); + std::list anAttributes = aFeature->data()->attributes( + ModelAPI_AttributeRefList::typeId()); + std::list::const_iterator anIt = anAttributes.begin(), aLast = anAttributes.end(); + bool aFoundObject = false; + for (; anIt != aLast && !aFoundObject; anIt++) { + std::shared_ptr aCurSelList = + std::dynamic_pointer_cast(*anIt); + for (int i = 0, aNb = aCurSelList->size(); i < aNb && !aFoundObject; i++) { + ObjectPtr anObject = aCurSelList->object(i); + FeaturePtr aFeature = std::dynamic_pointer_cast(anObject); + if (aFeature.get()) { + aFoundObject = anObjectFeature == aFeature; + } + } + } + return aFoundObject; + } +#endif } return false; } @@ -200,7 +229,7 @@ bool ModuleBase_OperationFeature::isDisplayedOnStart(ObjectPtr theObject) return myVisualizedObjects.find(theObject) != myVisualizedObjects.end(); } -void ModuleBase_OperationFeature::start() +bool ModuleBase_OperationFeature::start() { setIsModified(false); QString anId = getDescription()->operationId(); @@ -220,12 +249,12 @@ void ModuleBase_OperationFeature::start() // in order to update commands status in the workshop, to be exact the feature action // to be unchecked abort(); - return; + return false; } } //Already called startOperation(); emit started(); - + return true; } void ModuleBase_OperationFeature::abort() @@ -268,6 +297,13 @@ void ModuleBase_OperationFeature::abort() bool ModuleBase_OperationFeature::commit() { + ModuleBase_IPropertyPanel* aPanel = propertyPanel(); + if (aPanel) { + ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget(); + if (anActiveWidget && anActiveWidget->getValueState() == ModuleBase_ModelWidget::ModifiedInPP) { + anActiveWidget->storeValue(); + } + } if (canBeCommitted()) { emit beforeCommitted(); // the widgets of property panel should not process any events come from data mode @@ -297,52 +333,62 @@ bool ModuleBase_OperationFeature::commit() return false; } -void ModuleBase_OperationFeature::activateByPreselection() +ModuleBase_ModelWidget* ModuleBase_OperationFeature::activateByPreselection( + const std::string& theGreedAttributeId) { + ModuleBase_ModelWidget* aWidget = 0; if (myPreSelection.empty()) - return; - + return aWidget; + // equal vertices should not be used here ModuleBase_ISelection::filterSelectionOnEqualPoints(myPreSelection); - ModuleBase_ModelWidget* aFilledWgt = 0; ModuleBase_IPropertyPanel* aPropertyPanel = propertyPanel(); + ModuleBase_ModelWidget* aFilledWgt = 0; if (aPropertyPanel) { const QList& aWidgets = aPropertyPanel->modelWidgets(); + QList::const_iterator aWIt; + ModuleBase_ModelWidget* aWgt = 0; if (!aWidgets.empty()) { - ModuleBase_ModelWidget* aWgt = 0; - QList::const_iterator aWIt; - bool isSet = false; - // 1. apply the selection to controls - for (aWIt = aWidgets.constBegin(); aWIt != aWidgets.constEnd(); ++aWIt) { - aWgt = (*aWIt); - if (!aWgt->canSetValue()) - continue; - aPropertyPanel->setPreselectionWidget(aWgt); - if (!aWgt->setSelection(myPreSelection, true)) { - isSet = false; - break; - } else { - isSet = true; - aFilledWgt = aWgt; + if (!theGreedAttributeId.empty()) { + // set preselection to greed widget + for (aWIt = aWidgets.constBegin(); aWIt != aWidgets.constEnd(); ++aWIt) { + aWgt = (*aWIt); + if (aWgt->attributeID() == theGreedAttributeId) { + aPropertyPanel->setPreselectionWidget(aWgt); + aWgt->setSelection(myPreSelection, true); + aPropertyPanel->setPreselectionWidget(NULL); + aFilledWgt = aWgt; + break; + } + } + } + else { + bool isSet = false; + // 1. apply the selection to controls + for (aWIt = aWidgets.constBegin(); aWIt != aWidgets.constEnd(); ++aWIt) { + aWgt = (*aWIt); + if (!aWgt->canAcceptFocus()) + continue; + aPropertyPanel->setPreselectionWidget(aWgt); + if (!aWgt->setSelection(myPreSelection, true)) { + isSet = false; + break; + } else { + isSet = true; + aFilledWgt = aWgt; + } } } aPropertyPanel->setPreselectionWidget(NULL); // in order to redisplay object in the viewer, the update/redisplay signals should be flushed // it is better to perform it not in setSelection of each widget, but do it here, // after the preselection is processed - ModuleBase_ModelWidget::updateObject(myFeature); - - // 3. a signal should be emitted before the next widget activation - // because, the activation of the next widget will give a focus to the widget. As a result - // the value of the widget is initialized. And commit may happens until the value is entered. - if (aFilledWgt) - emit activatedByPreselection(); + ModuleBase_Tools::flushUpdated(myFeature); } - // 4. activate the next obligatory widget - aPropertyPanel->activateNextWidget(aFilledWgt); } - clearPreselection(); + + return aFilledWgt; } void ModuleBase_OperationFeature::setParentFeature(CompositeFeaturePtr theParent) @@ -368,13 +414,11 @@ FeaturePtr ModuleBase_OperationFeature::previousCurrentFeature() void ModuleBase_OperationFeature::initSelection(ModuleBase_ISelection* theSelection, ModuleBase_IViewer* theViewer) { - clearPreselection(); - - QList aPreSelected; + QList aPreSelected; // Check that the selected result are not results of operation feature FeaturePtr aFeature = feature(); if (aFeature) { - QList aSelected = theSelection->getSelected(ModuleBase_ISelection::AllControls); + QList aSelected = theSelection->getSelected(ModuleBase_ISelection::AllControls); std::list aResults = aFeature->results(); QObjectPtrList aResList; @@ -382,14 +426,20 @@ void ModuleBase_OperationFeature::initSelection(ModuleBase_ISelection* theSelect for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) aResList.append(*aIt); - foreach (ModuleBase_ViewerPrs aPrs, aSelected) { - if ((!aResList.contains(aPrs.object())) && (aPrs.object() != aFeature)) + foreach (ModuleBase_ViewerPrsPtr aPrs, aSelected) { + if ((!aResList.contains(aPrs->object())) && (aPrs->object() != aFeature)) aPreSelected.append(aPrs); } } else aPreSelected = theSelection->getSelected(ModuleBase_ISelection::AllControls); - myPreSelection = aPreSelected; + setPreselection(aPreSelected); +} + +void ModuleBase_OperationFeature::setPreselection(const QList& theValues) +{ + clearPreselection(); + myPreSelection = theValues; } void ModuleBase_OperationFeature::clearPreselection()