+ for (std::list<FeaturePtr>::iterator anIt = aRemove.begin(); anIt != aRemove.end(); ++anIt)
+ document()->removeFeature(*anIt);
+ return true;
+}
+
+
+static ObjectPtr findAxis(GeomShapePtr theAxisToCompare,
+ ObjectPtr theOX,
+ ObjectPtr theOY,
+ ObjectPtr theOZ)
+{
+ if (theAxisToCompare) {
+ ObjectPtr anAxes[] = { theOX, theOY, theOZ };
+ for (int i = 0; i < 3; ++i) {
+ ResultPtr anAx = std::dynamic_pointer_cast<ModelAPI_Result>(anAxes[i]);
+ if (anAx && theAxisToCompare->isEqual(anAx->shape()))
+ return anAxes[i];
+ }
+ }
+ return ObjectPtr();
+}
+
+static ObjectPtr findAxis(ObjectPtr theAxisToCompare,
+ ObjectPtr theOX,
+ ObjectPtr theOY,
+ ObjectPtr theOZ)
+{
+ if (theAxisToCompare == theOX)
+ return theOX;
+ else if (theAxisToCompare == theOY)
+ return theOY;
+ else if (theAxisToCompare == theOZ)
+ return theOZ;
+ // nothing helped, search by shape
+ ResultPtr anAxis = std::dynamic_pointer_cast<ModelAPI_Result>(theAxisToCompare);
+ return findAxis(anAxis ? anAxis->shape() : GeomShapePtr(), theOX, theOY, theOZ);
+}
+
+GeomShapePtr axisOnNewPlane(ObjectPtr theAxis, GeomAx3Ptr theOldPlane, GeomAx3Ptr theNewPlane)
+{
+ ResultPtr anAxis = std::dynamic_pointer_cast<ModelAPI_Result>(theAxis);
+ if (!anAxis)
+ return GeomShapePtr();
+
+ GeomEdgePtr anAxisEdge = anAxis->shape()->edge();
+ GeomLinePtr anAxisLine = anAxisEdge->line();
+ GeomDirPtr anAxisDir = anAxisLine->direction();
+
+ double aFirstParam, aLastParam;
+ anAxisEdge->getRange(aFirstParam, aLastParam);
+
+ if (theOldPlane->dirX()->isParallel(anAxisDir))
+ anAxisDir = theNewPlane->dirX();
+ else if (theOldPlane->dirY()->isParallel(anAxisDir))
+ anAxisDir = theNewPlane->dirY();
+ else if (theOldPlane->normal()->isParallel(anAxisDir))
+ anAxisDir = theNewPlane->normal();
+
+ GeomPointPtr aFirstPoint(new GeomAPI_Pnt(aFirstParam * anAxisDir->x(),
+ aFirstParam * anAxisDir->y(),
+ aFirstParam * anAxisDir->z()));
+ GeomPointPtr aLastPoint(new GeomAPI_Pnt(aLastParam * anAxisDir->x(),
+ aLastParam * anAxisDir->y(),
+ aLastParam * anAxisDir->z()));
+ return GeomAlgoAPI_EdgeBuilder::line(aFirstPoint, aLastPoint);
+}
+
+void SketchPlugin_Sketch::updateCoordinateAxis(ObjectPtr theSub, GeomAx3Ptr thePlane)
+{
+ FeaturePtr aFeature = ModelAPI_Feature::feature(theSub);
+ if (!aFeature)
+ return;
+
+ DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
+ ObjectPtr anOX = aRootDoc->objectByName(ModelAPI_ResultConstruction::group(), "OX");
+ ObjectPtr anOY = aRootDoc->objectByName(ModelAPI_ResultConstruction::group(), "OY");
+ ObjectPtr anOZ = aRootDoc->objectByName(ModelAPI_ResultConstruction::group(), "OZ");
+
+ AttributeSelectionPtr anExtFeature;
+ if (aFeature->getKind() == SketchPlugin_Projection::ID())
+ anExtFeature = aFeature->selection(SketchPlugin_Projection::EXTERNAL_FEATURE_ID());
+ else if (aFeature->getKind() == SketchPlugin_IntersectionPoint::ID())
+ anExtFeature = aFeature->selection(SketchPlugin_IntersectionPoint::EXTERNAL_FEATURE_ID());
+ else
+ return;
+
+ ObjectPtr aContext = anExtFeature->context();
+ GeomShapePtr aShape = anExtFeature->value();
+ if (!aShape) { // selected object is a construction
+ ObjectPtr anAxis = findAxis(aContext, anOX, anOY, anOZ);
+ GeomShapePtr aNewAxis = axisOnNewPlane(anAxis, myPlane, thePlane);
+ anAxis = findAxis(aNewAxis, anOX, anOY, anOZ);
+ if (anAxis)
+ anExtFeature->setValue(anAxis, aShape);
+ }