+
+std::shared_ptr<ModelAPI_Document> ModuleBase_Operation::document() const
+{
+ return ModelAPI_Session::get()->moduleDocument();
+}
+
+
+void ModuleBase_Operation::start()
+{
+ QString anId = getDescription()->operationId();
+ ModelAPI_Session::get()->startOperation(anId.toStdString());
+
+ if (!myIsEditing)
+ createFeature();
+
+ startOperation();
+ emit started();
+
+}
+
+void ModuleBase_Operation::postpone()
+{
+ postponeOperation();
+ emit postponed();
+}
+
+void ModuleBase_Operation::resume()
+{
+ resumeOperation();
+ emit resumed();
+}
+
+void ModuleBase_Operation::abort()
+{
+ abortOperation();
+ emit aborted();
+
+ stopOperation();
+
+ ModelAPI_Session::get()->abortOperation();
+ emit stopped();
+}
+
+bool ModuleBase_Operation::commit()
+{
+ if (canBeCommitted()) {
+ commitOperation();
+ // 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();
+
+ stopOperation();
+ emit stopped();
+ emit committed();
+
+ afterCommitOperation();
+ return true;
+ }
+ return false;
+}
+
+void ModuleBase_Operation::setRunning(bool theState)
+{
+ if (!theState) {
+ abort();
+ }
+}
+
+void ModuleBase_Operation::activateByPreselection()
+{
+ if (!myPropertyPanel || myPreSelection.empty()) {
+ myPropertyPanel->activateNextWidget(NULL);
+ return;
+ }
+ const QList<ModuleBase_ModelWidget*>& aWidgets = myPropertyPanel->modelWidgets();
+ if (aWidgets.empty()) {
+ myPropertyPanel->activateNextWidget(NULL);
+ return;
+ }
+
+ ModuleBase_ModelWidget* aWgt, *aFilledWgt = 0;
+ QList<ModuleBase_ModelWidget*>::const_iterator aWIt;
+ QList<ModuleBase_ViewerPrs>::const_iterator aPIt;
+ bool isSet = false;
+ for (aWIt = aWidgets.constBegin(), aPIt = myPreSelection.constBegin();
+ (aWIt != aWidgets.constEnd()) && (aPIt != myPreSelection.constEnd());
+ ++aWIt) {
+ aWgt = (*aWIt);
+ ModuleBase_ViewerPrs aValue = (*aPIt);
+ if (!aWgt->canSetValue())
+ continue;
+
+ ++aPIt;
+ if (!aWgt->setSelection(aValue)) {
+ isSet = false;
+ break;
+ } else {
+ isSet = true;
+ aFilledWgt = aWgt;
+ }
+ }
+
+ myPropertyPanel->activateNextWidget(aFilledWgt);
+ if (aFilledWgt)
+ emit activatedByPreselection();
+
+}
+
+void ModuleBase_Operation::setParentFeature(CompositeFeaturePtr theParent)
+{
+ myParentFeature = theParent;
+}
+
+CompositeFeaturePtr ModuleBase_Operation::parentFeature() const
+{
+ return myParentFeature;
+}
+
+void ModuleBase_Operation::initSelection(ModuleBase_ISelection* theSelection,
+ ModuleBase_IViewer* theViewer)
+{
+ clearPreselection();
+
+ QList<ModuleBase_ViewerPrs> aPreSelected;
+ // Check that the selected result are not results of operation feature
+ FeaturePtr aFeature = feature();
+ if (aFeature) {
+ QList<ModuleBase_ViewerPrs> aSelected = theSelection->getSelected();
+
+ std::list<ResultPtr> aResults = aFeature->results();
+ QObjectPtrList 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))
+ aPreSelected.append(aPrs);
+ }
+ } else
+ aPreSelected = theSelection->getSelected();
+
+ // convert the selection values to the values, which are set to the operation widgets
+
+ //Handle(V3d_View) aView = theViewer->activeView();
+ //foreach (ModuleBase_ViewerPrs aPrs, aPreSelected) {
+ // ModuleBase_WidgetValueFeature* aValue = new ModuleBase_WidgetValueFeature();
+ // aValue->setObject(aPrs.object());
+
+ // double aX, anY;
+ // if (getViewerPoint(aPrs, theViewer, aX, anY))
+ // aValue->setPoint(std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(aX, anY)));
+ // myPreSelection.append(aValue);
+ //}
+ myPreSelection = aPreSelected;
+}
+
+//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(std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(theX, theY)));
+// bool isApplyed = aActiveWgt->setValue(aValue);
+//
+// delete aValue;
+// myIsModified = (myIsModified || isApplyed);
+// return isApplyed;
+//}
+
+bool ModuleBase_Operation::getViewerPoint(ModuleBase_ViewerPrs thePrs,
+ ModuleBase_IViewer* theViewer,
+ double& theX, double& theY)
+{
+ return false;
+}
+
+void ModuleBase_Operation::clearPreselection()