X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModuleBase%2FModuleBase_OperationFeature.cpp;h=0471bfae79e26b601075e030af60a165015df91b;hb=8cd56d486b6e96b8814002f9f0f4acadd6cea11b;hp=82f6db270ae09966b8bd19e8afebe9fb66d37598;hpb=185eeb27c54a3c06946f9b3a4d99dae468daa125;p=modules%2Fshaper.git diff --git a/src/ModuleBase/ModuleBase_OperationFeature.cpp b/src/ModuleBase/ModuleBase_OperationFeature.cpp index 82f6db270..0471bfae7 100755 --- a/src/ModuleBase/ModuleBase_OperationFeature.cpp +++ b/src/ModuleBase/ModuleBase_OperationFeature.cpp @@ -49,6 +49,32 @@ ModuleBase_OperationFeature::~ModuleBase_OperationFeature() clearPreselection(); } +void ModuleBase_OperationFeature::setEditOperation(const bool theRestartTransaction) +{ + if (isEditOperation()) + return; + + 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 = true; + + propertyPanel()->setEditingMode(isEditOperation()); +} + FeaturePtr ModuleBase_OperationFeature::feature() const { return myFeature; @@ -60,17 +86,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() @@ -79,6 +97,9 @@ void ModuleBase_OperationFeature::startOperation() if (!aFeature.get() || !isEditOperation()) return; + if (aFeature.get() && isEditOperation()) + aFeature->setStable(false); + myVisualizedObjects.clear(); // store hidden result features std::list aResults = aFeature->results(); @@ -115,21 +136,10 @@ void ModuleBase_OperationFeature::stopOperation() if (myVisualizedObjects.find(aFeature) != myVisualizedObjects.end()) { aFeature->setDisplayed(false); } - aFeature->setStable(true); if (myVisualizedObjects.size() > 0) Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY)); } -void ModuleBase_OperationFeature::resumeOperation() -{ - ModuleBase_Operation::resumeOperation(); - //if (!myIsEditing) - setCurrentFeature(feature()); - //SessionPtr aMgr = ModelAPI_Session::get(); - //DocumentPtr aDoc = aMgr->activeDocument(); - //aDoc->setCurrentFeature(feature(), false); -} - FeaturePtr ModuleBase_OperationFeature::createFeature(const bool theFlushMessage) { if (myParentFeature.get()) { @@ -158,7 +168,6 @@ FeaturePtr ModuleBase_OperationFeature::createFeature(const bool theFlushMessage void ModuleBase_OperationFeature::setFeature(FeaturePtr theFeature) { myFeature = theFeature; - myFeature->setStable(false); myIsEditing = true; } @@ -183,7 +192,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(); @@ -192,6 +201,7 @@ void ModuleBase_OperationFeature::start() } ModelAPI_Session::get()->startOperation(anId.toStdString()); + emit beforeStarted(); startOperation(); if (!myIsEditing) { @@ -202,32 +212,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(); - // the parameter of current feature should be false, we should use all feature, not only visible - // in order to correctly save the previous feature of the nested operation, where the - // features can be not visible in the tree. The problem case is Edit sketch entitity(line) - // in the Sketch, created in ExtrusionCut operation. The entity disappears by commit. - // When sketch entity operation started, the sketch should be cashed here as the current. - // Otherwise(the flag is true), the ExtrusionCut is cashed, when commit happens, the sketch - // is disabled, sketch entity is disabled as extrusion cut is created earliest then sketch. - // As a result the sketch disappears from the viewer. However after commit it is displayed back. - myPreviousCurrentFeature = aDoc->currentFeature(false); - 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( @@ -243,21 +239,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(myPreviousCurrentFeature, false);//true); - if (!aIsOp) - aMgr->finishOperation(); - myPreviousCurrentFeature = FeaturePtr(); - } - abortOperation(); + if (myFeature.get()) + myFeature->setStable(true); + abortOperation(); stopOperation(); + 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 @@ -272,7 +260,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 @@ -282,27 +278,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) { - setCurrentFeature(myPreviousCurrentFeature); - /*DocumentPtr aDoc = aMgr->activeDocument(); - bool aIsOp = aMgr->isOperation(); - if (!aIsOp) - aMgr->startOperation(); - aDoc->setCurrentFeature(myPreviousCurrentFeature, true); - if (!aIsOp) - aMgr->finishOperation();*/ - myPreviousCurrentFeature = FeaturePtr(); - } - else { - /*CompositeFeaturePtr aCompositeFeature = ModelAPI_Tools::compositeOwner(feature()); - if (aCompositeFeature.get()) - setCurrentFeature(aCompositeFeature);//myPreviousCurrentFeature); - //else - // setCurrentFeature(feature());*/ - } commitOperation(); aMgr->finishOperation(); @@ -316,23 +296,13 @@ bool ModuleBase_OperationFeature::commit() return false; } -void ModuleBase_OperationFeature::setCurrentFeature(const FeaturePtr& theFeature) -{ - SessionPtr aMgr = ModelAPI_Session::get(); - DocumentPtr aDoc = aMgr->activeDocument(); - bool aIsOp = aMgr->isOperation(); - if (!aIsOp) - aMgr->startOperation(); - aDoc->setCurrentFeature(theFeature, false);//true); - if (!aIsOp) - aMgr->finishOperation(); -} - void ModuleBase_OperationFeature::activateByPreselection() { if (myPreSelection.empty()) return; + ModuleBase_ISelection::filterSelectionOnEqualPoints(myPreSelection); + ModuleBase_ModelWidget* aFilledWgt = 0; ModuleBase_IPropertyPanel* aPropertyPanel = propertyPanel(); if (aPropertyPanel) { @@ -384,6 +354,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) {