X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModuleBase%2FModuleBase_OperationFeature.cpp;h=950a20efa66a48108f84326212c7ac4af5920d19;hb=7e31817b90ba5e8208ffdec5e09f2b23ec196890;hp=ff49f71454cfc80d42835df98295220ff4ca8d28;hpb=03936c76cd52c555961e4636e640c12fe2d47f2f;p=modules%2Fshaper.git diff --git a/src/ModuleBase/ModuleBase_OperationFeature.cpp b/src/ModuleBase/ModuleBase_OperationFeature.cpp index ff49f7145..950a20efa 100755 --- a/src/ModuleBase/ModuleBase_OperationFeature.cpp +++ b/src/ModuleBase/ModuleBase_OperationFeature.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include @@ -48,6 +49,36 @@ ModuleBase_OperationFeature::~ModuleBase_OperationFeature() clearPreselection(); } +void ModuleBase_OperationFeature::setEditOperation(const bool& isEditState + /*const bool theRestartTransaction*/) +{ + 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(); + SessionPtr aMgr = ModelAPI_Session::get(); + ModelAPI_Session::get()->finishOperation(); + + // start new edit operation + myIsEditing = true; + QString anId = getDescription()->operationId(); + if (myIsEditing) { + anId = anId.append(EditSuffix()); + } + ModelAPI_Session::get()->startOperation(anId.toStdString()); + emit beforeStarted(); + } else*/ + myIsEditing = isEditState; + + propertyPanel()->setEditingMode(isEditOperation()); +} + FeaturePtr ModuleBase_OperationFeature::feature() const { return myFeature; @@ -59,17 +90,58 @@ 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 ); + std::string anError = ModelAPI_Tools::getFeatureError(myFeature); + return anError.empty(); +} + +void ModuleBase_OperationFeature::startOperation() +{ + FeaturePtr aFeature = feature(); + if (!aFeature.get() || !isEditOperation()) + return; - return aValid && isDone; + if (aFeature.get() && isEditOperation()) + aFeature->setStable(false); + + myVisualizedObjects.clear(); + // store hidden result features + std::list aResults = aFeature->results(); + std::list::const_iterator aIt; + for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) { + ObjectPtr anObject = *aIt; + if (anObject.get() && !anObject->isDisplayed()) { + myVisualizedObjects.insert(*aIt); + anObject->setDisplayed(true); + } + } + if (!aFeature->isDisplayed()) { + myVisualizedObjects.insert(aFeature); + aFeature->setDisplayed(true); + } + Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY)); +} + +void ModuleBase_OperationFeature::stopOperation() +{ + FeaturePtr aFeature = feature(); + if (!aFeature.get() || !isEditOperation()) + return; + + // store hidden result features + std::list aResults = aFeature->results(); + std::list::const_iterator aIt; + for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) { + ObjectPtr anObject = *aIt; + if (anObject.get() && myVisualizedObjects.find(anObject) != myVisualizedObjects.end()) { + anObject->setDisplayed(false); + } + } + if (myVisualizedObjects.find(aFeature) != myVisualizedObjects.end()) { + aFeature->setDisplayed(false); + } + if (myVisualizedObjects.size() > 0) + Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY)); } FeaturePtr ModuleBase_OperationFeature::createFeature(const bool theFlushMessage) @@ -119,7 +191,12 @@ bool ModuleBase_OperationFeature::hasObject(ObjectPtr theObj) const return false; } -void ModuleBase_OperationFeature::start() +bool ModuleBase_OperationFeature::isDisplayedOnStart(ObjectPtr theObject) +{ + return myVisualizedObjects.find(theObject) != myVisualizedObjects.end(); +} + +bool ModuleBase_OperationFeature::start() { setIsModified(false); QString anId = getDescription()->operationId(); @@ -128,6 +205,7 @@ void ModuleBase_OperationFeature::start() } ModelAPI_Session::get()->startOperation(anId.toStdString()); + emit beforeStarted(); startOperation(); if (!myIsEditing) { @@ -138,24 +216,18 @@ 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; } } - /// Set current feature and remeber old current feature - if (myIsEditing) { - SessionPtr aMgr = ModelAPI_Session::get(); - DocumentPtr aDoc = aMgr->activeDocument(); - myCurrentFeature = aDoc->currentFeature(true); - aDoc->setCurrentFeature(feature(), false); - } - - startOperation(); + //Already called startOperation(); emit started(); - + return true; } void ModuleBase_OperationFeature::abort() { + emit beforeAborted(); + // the viewer update should be blocked in order to avoid the features blinking before they are // hidden std::shared_ptr aMsg = std::shared_ptr( @@ -171,24 +243,13 @@ void ModuleBase_OperationFeature::abort() if (aPropertyPanel) aPropertyPanel->cleanContent(); - SessionPtr aMgr = ModelAPI_Session::get(); - if (myIsEditing) { - DocumentPtr aDoc = aMgr->activeDocument(); - bool aIsOp = aMgr->isOperation(); - if (!aIsOp) - aMgr->startOperation(); - aDoc->setCurrentFeature(myCurrentFeature, true); - if (!aIsOp) - aMgr->finishOperation(); - myCurrentFeature = FeaturePtr(); - } - abortOperation(); + if (myFeature.get()) + myFeature->setStable(true); + abortOperation(); stopOperation(); - // is is necessary to deactivate current widgets before the model operation is aborted - // because abort removes the feature and activated filters should not check it - propertyPanel()->cleanContent(); + SessionPtr aMgr = ModelAPI_Session::get(); aMgr->abortOperation(); emit stopped(); // the viewer update should be unblocked in order to avoid the features blinking before they are @@ -203,7 +264,15 @@ 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 // after commit clicked. Some signal such as redisplay/create influence on content // of the object browser and viewer context. Therefore it influence to the current @@ -213,18 +282,11 @@ bool ModuleBase_OperationFeature::commit() if (aPropertyPanel) aPropertyPanel->cleanContent(); + myFeature->setStable(true); + SessionPtr aMgr = ModelAPI_Session::get(); /// Set current feature and remeber old current feature - if (myIsEditing) { - DocumentPtr aDoc = aMgr->activeDocument(); - bool aIsOp = aMgr->isOperation(); - if (!aIsOp) - aMgr->startOperation(); - aDoc->setCurrentFeature(myCurrentFeature, true); - if (!aIsOp) - aMgr->finishOperation(); - myCurrentFeature = FeaturePtr(); - } + commitOperation(); aMgr->finishOperation(); @@ -243,6 +305,8 @@ void ModuleBase_OperationFeature::activateByPreselection() if (myPreSelection.empty()) return; + ModuleBase_ISelection::filterSelectionOnEqualPoints(myPreSelection); + ModuleBase_ModelWidget* aFilledWgt = 0; ModuleBase_IPropertyPanel* aPropertyPanel = propertyPanel(); if (aPropertyPanel) { @@ -294,6 +358,16 @@ CompositeFeaturePtr ModuleBase_OperationFeature::parentFeature() const return myParentFeature; } +void ModuleBase_OperationFeature::setPreviousCurrentFeature(const FeaturePtr& theFeature) +{ + myPreviousCurrentFeature = theFeature; +} + +FeaturePtr ModuleBase_OperationFeature::previousCurrentFeature() +{ + return myPreviousCurrentFeature; +} + void ModuleBase_OperationFeature::initSelection(ModuleBase_ISelection* theSelection, ModuleBase_IViewer* theViewer) { @@ -347,9 +421,9 @@ void ModuleBase_OperationFeature::setPropertyPanel(ModuleBase_IPropertyPanel* th // 4. activate the first obligatory widget theProp->activateNextWidget(NULL); } -} - -bool ModuleBase_OperationFeature::isGranted(QString theId) const -{ - return myNestedFeatures.contains(theId); + else { + // set focus on Ok button in order to operation manager could process Enter press + if (theProp) + theProp->setFocusOnOkButton(); + } }