+
+void PartSet_OperationSketch::stopOperation()
+{
+ PartSet_OperationSketchBase::stopOperation();
+ emit featureConstructed(feature(), FM_Hide);
+ emit closeLocalContext();
+
+ FeaturePtr aFeature = feature();
+ std::list<ResultPtr> aResults = aFeature->results();
+ std::list<ResultPtr>::const_iterator aIt;
+ for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) {
+ ModelAPI_EventCreator::get()->sendUpdated(
+ *aIt, Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY));
+ }
+ //ModelAPI_EventCreator::get()->sendUpdated(aFeature,
+ // Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY));
+}
+
+bool PartSet_OperationSketch::isNestedOperationsEnabled() const
+{
+ return hasSketchPlane();
+}
+
+void PartSet_OperationSketch::startOperation()
+{
+ PartSet_OperationSketchBase::startOperation();
+ if (!isEditOperation())
+ emit fitAllView();
+}
+
+bool PartSet_OperationSketch::hasSketchPlane() const
+{
+ bool aHasPlane = false;
+
+ if (feature()) {
+ boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
+ AttributeDoublePtr anAttr;
+ boost::shared_ptr<GeomDataAPI_Dir> aNormal = boost::dynamic_pointer_cast<GeomDataAPI_Dir>(
+ aData->attribute(SketchPlugin_Sketch::NORM_ID()));
+ aHasPlane = aNormal && !(aNormal->x() == 0 && aNormal->y() == 0 && aNormal->z() == 0);
+ }
+ return aHasPlane;
+}
+
+void PartSet_OperationSketch::setSketchPlane(const TopoDS_Shape& theShape)
+{
+ if (theShape.IsNull())
+ return;
+
+ // get selected shape
+ boost::shared_ptr<GeomAPI_Shape> aGShape(new GeomAPI_Shape);
+ aGShape->setImpl(new TopoDS_Shape(theShape));
+
+ // get plane parameters
+ boost::shared_ptr<GeomAPI_Pln> aPlane = GeomAlgoAPI_FaceBuilder::plane(aGShape);
+
+ // set plane parameters to feature
+ boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
+ double anA, aB, aC, aD;
+ aPlane->coefficients(anA, aB, aC, aD);
+
+ // calculate attributes of the sketch
+ boost::shared_ptr<GeomAPI_Dir> aNormDir(new GeomAPI_Dir(anA, aB, aC));
+ boost::shared_ptr<GeomAPI_XYZ> aCoords = aNormDir->xyz();
+ boost::shared_ptr<GeomAPI_XYZ> aZero(new GeomAPI_XYZ(0, 0, 0));
+ aCoords = aCoords->multiplied(-aD * aCoords->distance(aZero));
+ boost::shared_ptr<GeomAPI_Pnt> anOrigPnt(new GeomAPI_Pnt(aCoords));
+ // X axis is preferable to be dirX on the sketch
+ const double tol = Precision::Confusion();
+ bool isX = fabs(anA - 1.0) < tol && fabs(aB) < tol && fabs(aC) < tol;
+ boost::shared_ptr<GeomAPI_Dir> aTempDir(
+ isX ? new GeomAPI_Dir(0, 1, 0) : new GeomAPI_Dir(1, 0, 0));
+ boost::shared_ptr<GeomAPI_Dir> aYDir(new GeomAPI_Dir(aNormDir->cross(aTempDir)));
+ boost::shared_ptr<GeomAPI_Dir> aXDir(new GeomAPI_Dir(aYDir->cross(aNormDir)));
+
+ boost::shared_ptr<GeomDataAPI_Point> anOrigin = boost::dynamic_pointer_cast<GeomDataAPI_Point>(
+ aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
+ anOrigin->setValue(anOrigPnt);
+ boost::shared_ptr<GeomDataAPI_Dir> aNormal = boost::dynamic_pointer_cast<GeomDataAPI_Dir>(
+ aData->attribute(SketchPlugin_Sketch::NORM_ID()));
+ aNormal->setValue(aNormDir);
+ boost::shared_ptr<GeomDataAPI_Dir> aDirX = boost::dynamic_pointer_cast<GeomDataAPI_Dir>(
+ aData->attribute(SketchPlugin_Sketch::DIRX_ID()));
+ aDirX->setValue(aXDir);
+ boost::shared_ptr<GeomDataAPI_Dir> aDirY = boost::dynamic_pointer_cast<GeomDataAPI_Dir>(
+ aData->attribute(SketchPlugin_Sketch::DIRY_ID()));
+ aDirY->setValue(aYDir);
+ boost::shared_ptr<GeomAPI_Dir> aDir = aPlane->direction();
+
+ flushUpdated();
+
+ emit featureConstructed(feature(), FM_Hide);
+ emit closeLocalContext();
+ emit planeSelected(aDir->x(), aDir->y(), aDir->z());
+}
+
+
+bool PartSet_OperationSketch::isValid(ModuleBase_IOperation* theOperation) const
+{
+ PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(theOperation);
+ return aPreviewOp != NULL;
+}
+