+
+boost::shared_ptr<ModelAPI_Document> 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<ModuleBase_ModelWidget*>& aWidgets = myPropertyPanel->modelWidgets();
+ if (aWidgets.empty())
+ return false;
+
+ ModuleBase_ModelWidget* aWgt;
+ ModuleBase_ViewerPrs aPrs;
+ QList<ModuleBase_ModelWidget*>::const_iterator aWIt;
+ QList<ModuleBase_ViewerPrs>::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<ModuleBase_ViewerPrs> aSelected = theSelection->getSelected();
+ FeaturePtr aFeature = feature();
+ if (aFeature) {
+ std::list<ResultPtr> aResults = aFeature->results();
+ QList<ObjectPtr> aResList;
+ std::list<ResultPtr>::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<GeomAPI_Pnt2d>(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*)));
+}