X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModuleBase%2FModuleBase_Operation.cpp;h=cd728aa7adcb2711218549b172b0062bd6b83df1;hb=5b841e9801c659d762d708378df8c4d85565fda0;hp=4a980a1dc2b8b0dc534ca40968f0b57ca247bc57;hpb=3ce4e2cad0e6802282a5a1d10c49c041e8a9f287;p=modules%2Fshaper.git diff --git a/src/ModuleBase/ModuleBase_Operation.cpp b/src/ModuleBase/ModuleBase_Operation.cpp index 4a980a1dc..cd728aa7a 100644 --- a/src/ModuleBase/ModuleBase_Operation.cpp +++ b/src/ModuleBase/ModuleBase_Operation.cpp @@ -9,6 +9,10 @@ #include "ModuleBase_OperationDescription.h" #include "ModuleBase_ModelWidget.h" +#include "ModuleBase_WidgetValueFeature.h" +#include "ModuleBase_ViewerPrs.h" +#include "ModuleBase_IPropertyPanel.h" +#include "ModuleBase_ISelection.h" #include #include @@ -17,7 +21,11 @@ #include #include #include +#include #include +#include + +#include #include @@ -26,12 +34,17 @@ #endif ModuleBase_Operation::ModuleBase_Operation(const QString& theId, QObject* theParent) -: ModuleBase_IOperation(theId, theParent) + : QObject(theParent), + myIsEditing(false), + myIsModified(false), + myPropertyPanel(NULL) { + myDescription = new ModuleBase_OperationDescription(theId); } ModuleBase_Operation::~ModuleBase_Operation() { + delete myDescription; } QString ModuleBase_Operation::id() const @@ -44,6 +57,16 @@ FeaturePtr ModuleBase_Operation::feature() const return myFeature; } +bool ModuleBase_Operation::isValid() const +{ + if (!myFeature) + return true; // rename operation + //Get validators for the Id + SessionPtr aMgr = ModelAPI_Session::get(); + ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); + return aFactory->validate(myFeature); +} + bool ModuleBase_Operation::isNestedOperationsEnabled() const { return true; @@ -51,11 +74,11 @@ bool ModuleBase_Operation::isNestedOperationsEnabled() const void ModuleBase_Operation::storeCustomValue() { - if(!myFeature){ - #ifdef _DEBUG + if (!myFeature) { +#ifdef _DEBUG qDebug() << "ModuleBase_Operation::storeCustom: " << - "trying to store value without opening a transaction."; - #endif + "trying to store value without opening a transaction."; +#endif return; } @@ -64,16 +87,10 @@ void ModuleBase_Operation::storeCustomValue() aCustom->storeValue(); } -void ModuleBase_Operation::onWidgetActivated(ModuleBase_ModelWidget* theWidget) -{ -} - void ModuleBase_Operation::startOperation() { if (!myIsEditing) createFeature(); - //emit callSlot(); - //commit(); } void ModuleBase_Operation::stopOperation() @@ -86,7 +103,6 @@ void ModuleBase_Operation::abortOperation() void ModuleBase_Operation::commitOperation() { - if (myFeature) myFeature->execute(); } void ModuleBase_Operation::afterCommitOperation() @@ -95,26 +111,7 @@ void ModuleBase_Operation::afterCommitOperation() bool ModuleBase_Operation::canBeCommitted() const { - if (ModuleBase_IOperation::canBeCommitted()) { -/* FeaturePtr aFeature = feature(); - std::string aId = aFeature->getKind(); - - PluginManagerPtr aMgr = ModelAPI_PluginManager::get(); - ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); - std::list aValidators; - aFactory->validators(aId, aValidators); - std::list::const_iterator aIt; - for (aIt = aValidators.cbegin(); aIt != aValidators.cend(); ++aIt) { - const ModuleBase_FeatureValidator* aFValidator = - dynamic_cast(*aIt); - if (aFValidator) { - if (!aFValidator->isValid(aFeature)) - return false; - } - }*/ - return true; - } - return false; + return true; } void ModuleBase_Operation::flushUpdated() @@ -127,19 +124,25 @@ 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 (myFeature) { // TODO: generate an error if feature was not created + 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; - myFeature->execute(); + // Model update should call "execute" of a feature. + //myFeature->execute(); // Init default values /*QList aWidgets = getDescription()->modelWidgets(); - QList::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end(); - for (; anIt != aLast; anIt++) { - (*anIt)->storeValue(aFeature); - }*/ + QList::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end(); + for (; anIt != aLast; anIt++) { + (*anIt)->storeValue(aFeature); + }*/ } if (theFlushMessage) @@ -150,11 +153,6 @@ FeaturePtr ModuleBase_Operation::createFeature(const bool theFlushMessage) void ModuleBase_Operation::setFeature(FeaturePtr theFeature) { myFeature = theFeature; -} - -void ModuleBase_Operation::setEditingFeature(FeaturePtr theFeature) -{ - setFeature(theFeature); myIsEditing = true; } @@ -172,4 +170,166 @@ bool ModuleBase_Operation::hasObject(ObjectPtr theObj) const } } return false; -} \ No newline at end of file +} + + +boost::shared_ptr ModuleBase_Operation::document() const +{ + return ModelAPI_Session::get()->moduleDocument(); +} + + +void ModuleBase_Operation::start() +{ + ModelAPI_Session::get()->startOperation(); + + startOperation(); + emit started(); +} + +void ModuleBase_Operation::resume() +{ + if (myPropertyPanel) + connect(myPropertyPanel, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)), + this, SLOT(onWidgetActivated(ModuleBase_ModelWidget*))); + emit resumed(); +} + +void ModuleBase_Operation::abort() +{ + abortOperation(); + emit aborted(); + if (myPropertyPanel) + disconnect(myPropertyPanel, 0, this, 0); + + stopOperation(); + + ModelAPI_Session::get()->abortOperation(); + emit stopped(); +} + +bool ModuleBase_Operation::commit() +{ + if (canBeCommitted()) { + commitOperation(); + emit committed(); + + if (myPropertyPanel) + disconnect(myPropertyPanel, 0, this, 0); + + stopOperation(); + ModelAPI_Session::get()->finishOperation(); + + emit stopped(); + + afterCommitOperation(); + return true; + } + return false; +} + +void ModuleBase_Operation::setRunning(bool theState) +{ + if (!theState) { + abort(); + } +} + +bool ModuleBase_Operation::activateByPreselection() +{ + if (!myPropertyPanel) + return false; + if (myPreSelection.empty()) + return false; + const QList& aWidgets = myPropertyPanel->modelWidgets(); + if (aWidgets.empty()) + return false; + + ModuleBase_ModelWidget* aWgt; + ModuleBase_ViewerPrs aPrs; + QList::const_iterator aWIt; + QList::const_iterator aPIt; + 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 (!aWgt->setValue(&aValue)) + break; + } + if (canBeCommitted()) { + // if all widgets are filled with selection + commit(); + return true; + } + + //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(ModuleBase_ISelection* theSelection, + ModuleBase_IViewer* /*theViewer*/) +{ + 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(); + //if (theWidget && myPropertyPanel) { + // myPropertyPanel->activateNextWidget(); + //// //emit activateNextWidget(myActiveWidget); + //} +} + +bool ModuleBase_Operation::setWidgetValue(ObjectPtr theFeature, double theX, double theY) +{ + ModuleBase_ModelWidget* aActiveWgt = myPropertyPanel->activeWidget(); + if (!aActiveWgt) + return false; + ModuleBase_WidgetValueFeature* aValue = new ModuleBase_WidgetValueFeature(); + aValue->setObject(theFeature); + aValue->setPoint(boost::shared_ptr(new GeomAPI_Pnt2d(theX, theY))); + bool isApplyed = aActiveWgt->setValue(aValue); + + delete aValue; + myIsModified = (myIsModified || isApplyed); + return isApplyed; +} + + +void ModuleBase_Operation::setPropertyPanel(ModuleBase_IPropertyPanel* theProp) +{ + myPropertyPanel = theProp; + connect(myPropertyPanel, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)), this, + SLOT(onWidgetActivated(ModuleBase_ModelWidget*))); +}