X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModuleBase%2FModuleBase_Operation.cpp;h=b3bf0b07572308f26b62a2fc2c177a4ae2eb24dc;hb=28c90c232ffe159b88edd156286a398bfa3bb73b;hp=d8f50a4cd51e1a94f8d264df51c001741676dae5;hpb=c533d1d93579c5841081a310616b1e232baa23c6;p=modules%2Fshaper.git diff --git a/src/ModuleBase/ModuleBase_Operation.cpp b/src/ModuleBase/ModuleBase_Operation.cpp index d8f50a4cd..b3bf0b075 100644 --- a/src/ModuleBase/ModuleBase_Operation.cpp +++ b/src/ModuleBase/ModuleBase_Operation.cpp @@ -12,6 +12,7 @@ #include "ModuleBase_WidgetValueFeature.h" #include "ModuleBase_ViewerPrs.h" #include "ModuleBase_IPropertyPanel.h" +#include "ModuleBase_ISelection.h" #include #include @@ -20,12 +21,17 @@ #include #include #include +#include #include +#include #include #include +#include +#include + #ifdef _DEBUG #include #endif @@ -121,10 +127,15 @@ void ModuleBase_Operation::flushCreated() Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED)); } -FeaturePtr ModuleBase_Operation::createFeature(const bool theFlushMessage) +FeaturePtr ModuleBase_Operation::createFeature( + const bool theFlushMessage, CompositeFeaturePtr theCompositeFeature) { - boost::shared_ptr aDoc = document(); - myFeature = aDoc->addFeature(getDescription()->operationId().toStdString()); + if (theCompositeFeature) { + myFeature = theCompositeFeature->addFeature(getDescription()->operationId().toStdString()); + } else { + boost::shared_ptr aDoc = document(); + myFeature = aDoc->addFeature(getDescription()->operationId().toStdString()); + } if (myFeature) { // TODO: generate an error if feature was not created myIsModified = true; // Model update should call "execute" of a feature. @@ -182,8 +193,8 @@ void ModuleBase_Operation::start() void ModuleBase_Operation::resume() { if (myPropertyPanel) - connect(myPropertyPanel, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)), this, - SLOT(onWidgetActivated(ModuleBase_ModelWidget*))); + connect(myPropertyPanel, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)), + this, SLOT(onWidgetActivated(ModuleBase_ModelWidget*))); emit resumed(); } @@ -210,8 +221,14 @@ bool ModuleBase_Operation::commit() disconnect(myPropertyPanel, 0, this, 0); stopOperation(); + // check whether there are modifications performed during the current operation + // in the model + // in case if there are no modifications, do not increase the undo/redo stack + if (ModelAPI_Session::get()->isModified()) + ModelAPI_Session::get()->finishOperation(); + else + ModelAPI_Session::get()->abortOperation(); - ModelAPI_Session::get()->finishOperation(); emit stopped(); afterCommitOperation(); @@ -227,33 +244,92 @@ void ModuleBase_Operation::setRunning(bool theState) } } -void ModuleBase_Operation::activateByPreselection() +bool ModuleBase_Operation::activateByPreselection() { if (!myPropertyPanel) - return; - ModuleBase_ModelWidget* aActiveWgt = myPropertyPanel->activeWidget(); - if ((myPreSelection.size() > 0) && aActiveWgt) { - const ModuleBase_ViewerPrs& aPrs = myPreSelection.front(); + return false; + if (myPreSelection.empty()) + return false; + const QList& aWidgets = myPropertyPanel->modelWidgets(); + if (aWidgets.empty()) + return false; + + ModuleBase_ModelWidget* aWgt, *aFilledWgt = 0; + ModuleBase_ViewerPrs aPrs; + QList::const_iterator aWIt; + QList::const_iterator aPIt; + bool isSet = false; + for (aWIt = aWidgets.constBegin(), aPIt = myPreSelection.constBegin(); + (aWIt != aWidgets.constEnd()) && (aPIt != myPreSelection.constEnd()); + ++aWIt, ++aPIt) { + aWgt = (*aWIt); + aPrs = (*aPIt); ModuleBase_WidgetValueFeature aValue; aValue.setObject(aPrs.object()); - if (aActiveWgt->setValue(&aValue)) { - myPreSelection.remove(aPrs); - myPropertyPanel->activateNextWidget(); + // Check if the selection has a selected point + // for today it is impossible to do because + // the selected point demands convertation to Sketch plane 2d + if (!aWgt->setValue(&aValue)) { + isSet = false; + break; + } else { + isSet = true; + aFilledWgt = aWgt; + } + } + if (isSet && canBeCommitted()) { + // if all widgets are filled with selection + commit(); + return true; + } + else { + //activate next widget + if (aFilledWgt) { + myPropertyPanel->activateNextWidget(aFilledWgt); + return true; } - // If preselection is enough to make a valid feature - apply it immediately } + + //ModuleBase_ModelWidget* aActiveWgt = myPropertyPanel->activeWidget(); + //if ((myPreSelection.size() > 0) && aActiveWgt) { + // const ModuleBase_ViewerPrs& aPrs = myPreSelection.first(); + // ModuleBase_WidgetValueFeature aValue; + // aValue.setObject(aPrs.object()); + // if (aActiveWgt->setValue(&aValue)) { + // myPreSelection.removeOne(aPrs); + // myPropertyPanel->activateNextWidget(); + // } + // // If preselection is enough to make a valid feature - apply it immediately + //} + return false; } -void ModuleBase_Operation::initSelection( - const std::list& theSelected, - const std::list& /*theHighlighted*/) +void ModuleBase_Operation::initSelection(ModuleBase_ISelection* theSelection, + ModuleBase_IViewer* /*theViewer*/) { - myPreSelection = theSelected; + myPreSelection.clear(); + + // Check that the selected result are not results of operation feature + QList aSelected = theSelection->getSelected(); + FeaturePtr aFeature = feature(); + if (aFeature) { + std::list aResults = aFeature->results(); + QList aResList; + std::list::const_iterator aIt; + for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) + aResList.append(*aIt); + + foreach (ModuleBase_ViewerPrs aPrs, aSelected) { + if ((!aResList.contains(aPrs.object())) && (aPrs.object() != aFeature)) + myPreSelection.append(aPrs); + } + } else + myPreSelection = aSelected; } void ModuleBase_Operation::onWidgetActivated(ModuleBase_ModelWidget* theWidget) { - activateByPreselection(); + //activateByPreselection(); //if (theWidget && myPropertyPanel) { // myPropertyPanel->activateNextWidget(); //// //emit activateNextWidget(myActiveWidget);