X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModuleBase%2FModuleBase_Operation.cpp;h=a28d62d88e7dcc089b03b95b41beaf2412c84254;hb=164361234cb019c478ad6f254b27a6c9cd799337;hp=31fce07181390367c1e3526fa7e9db2af11c2e8d;hpb=a993a2e680b4a5a2e8b9ad9c998dc872ff962702;p=modules%2Fshaper.git diff --git a/src/ModuleBase/ModuleBase_Operation.cpp b/src/ModuleBase/ModuleBase_Operation.cpp index 31fce0718..a28d62d88 100644 --- a/src/ModuleBase/ModuleBase_Operation.cpp +++ b/src/ModuleBase/ModuleBase_Operation.cpp @@ -9,24 +9,45 @@ #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 #include #include #include +#include +#include +#include +#include +#include + +#include + +#include + +#include +#include #ifdef _DEBUG #include #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 @@ -34,51 +55,45 @@ QString ModuleBase_Operation::id() const return getDescription()->operationId(); } -boost::shared_ptr ModuleBase_Operation::feature() const +FeaturePtr ModuleBase_Operation::feature() const { return myFeature; } -bool ModuleBase_Operation::isNestedOperationsEnabled() +bool ModuleBase_Operation::isValid() const { - return true; + 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); } -void ModuleBase_Operation::storeReal(double theValue) +bool ModuleBase_Operation::isNestedOperationsEnabled() const { - if(!myFeature){ - #ifdef _DEBUG - qDebug() << "ModuleBase_Operation::storeReal: " << - "trying to store value without opening a transaction."; - #endif - return; - } - QString anId = sender()->objectName(); - boost::shared_ptr aData = myFeature->data(); - boost::shared_ptr aReal = aData->real(anId.toStdString()); - aReal->setValue(theValue); + return true; } 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; } ModuleBase_ModelWidget* aCustom = dynamic_cast(sender()); if (aCustom) - aCustom->storeValue(myFeature); + aCustom->storeValue(); } void ModuleBase_Operation::startOperation() { - setFeature(createFeature()); - //emit callSlot(); - //commit(); + if (!myIsEditing) + createFeature(); } void ModuleBase_Operation::stopOperation() @@ -91,20 +106,240 @@ void ModuleBase_Operation::abortOperation() void ModuleBase_Operation::commitOperation() { - if (myFeature) myFeature->execute(); } -boost::shared_ptr ModuleBase_Operation::createFeature() +void ModuleBase_Operation::afterCommitOperation() +{ +} + +bool ModuleBase_Operation::canBeCommitted() const +{ + return true; +} + +void ModuleBase_Operation::flushUpdated() +{ + Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); +} + +void ModuleBase_Operation::flushCreated() +{ + Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED)); +} + +FeaturePtr ModuleBase_Operation::createFeature( + const bool theFlushMessage, CompositeFeaturePtr theCompositeFeature) { - boost::shared_ptr aDoc = document(); - boost::shared_ptr aFeature = aDoc->addFeature( - getDescription()->operationId().toStdString()); - if (aFeature) // TODO: generate an error if feature was not created - aFeature->execute(); - return aFeature; + 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. + //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); + }*/ + } + + if (theFlushMessage) + flushCreated(); + return myFeature; } -void ModuleBase_Operation::setFeature(boost::shared_ptr theFeature) +void ModuleBase_Operation::setFeature(FeaturePtr theFeature) { myFeature = theFeature; + myIsEditing = true; +} + +bool ModuleBase_Operation::hasObject(ObjectPtr theObj) const +{ + FeaturePtr aFeature = feature(); + if (aFeature) { + if (aFeature == theObj) + return true; + std::list aResults = aFeature->results(); + std::list::const_iterator aIt; + for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) { + if ((*aIt) == theObj) + return true; + } + } + return false; +} + + +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; + 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()); + // 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; + } + if (isSet && 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*))); }