return thePoint2D->to3D(aC->pnt(), aX->dir(), aY);
}
-ResultPtr PartSet_Tools::createFixedObjectByExternal(const TopoDS_Shape& theShape,
- const ObjectPtr& theObject,
- CompositeFeaturePtr theSketch)
+ResultPtr PartSet_Tools::findFixedObjectByExternal(const TopoDS_Shape& theShape,
+ const ObjectPtr& theObject,
+ CompositeFeaturePtr theSketch)
{
+ ResultPtr aResult;
if (theShape.ShapeType() == TopAbs_EDGE) {
// Check that we already have such external edge
std::shared_ptr<GeomAPI_Edge> aInEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge());
aInEdge->setImpl(new TopoDS_Shape(theShape));
- ResultPtr aResult = findExternalEdge(theSketch, aInEdge);
- if (aResult)
- return aResult;
+ aResult = findExternalEdge(theSketch, aInEdge);
+ }
+ if (theShape.ShapeType() == TopAbs_VERTEX) {
+ std::shared_ptr<GeomAPI_Vertex> aInVert = std::shared_ptr<GeomAPI_Vertex>(new GeomAPI_Vertex());
+ aInVert->setImpl(new TopoDS_Shape(theShape));
+ aResult = findExternalVertex(theSketch, aInVert);
+ }
+ return aResult;
+}
- // If not found then we have to create new
+ResultPtr PartSet_Tools::createFixedObjectByExternal(const TopoDS_Shape& theShape,
+ const ObjectPtr& theObject,
+ CompositeFeaturePtr theSketch)
+{
+ if (theShape.ShapeType() == TopAbs_EDGE) {
Standard_Real aStart, aEnd;
Handle(V3d_View) aNullView;
FeaturePtr aMyFeature;
}
}
if (theShape.ShapeType() == TopAbs_VERTEX) {
- std::shared_ptr<GeomAPI_Vertex> aInVert = std::shared_ptr<GeomAPI_Vertex>(new GeomAPI_Vertex());
- aInVert->setImpl(new TopoDS_Shape(theShape));
- ResultPtr aResult = findExternalVertex(theSketch, aInVert);
- if (aResult)
- return aResult;
-
FeaturePtr aMyFeature = theSketch->addFeature(SketchPlugin_Point::ID());
if (aMyFeature) {
static std::shared_ptr<GeomAPI_Pnt> point3D(std::shared_ptr<GeomAPI_Pnt2d> thePoint2D,
CompositeFeaturePtr theSketch);
+ /// Finds a line (arc or circle) by given edge
+ /// \param theShape an edge
+ /// \param theObject a selected result object
+ /// \param theSketch a sketch feature
+ /// \return result of found feature or NULL
+ static ResultPtr findFixedObjectByExternal(const TopoDS_Shape& theShape,
+ const ObjectPtr& theObject,
+ CompositeFeaturePtr theSketch);
+
/// Creates a line (arc or circle) by given edge
/// Created line will have fixed constraint
/// \param theShape an edge
bool PartSet_WidgetConstraintShapeSelector::setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape)
{
- ObjectPtr aSelectedObject = theSelectedObject;
+ // initially the method is wrote to create an external object. Since the parent widget creates it,
+ // the redefinition is not necessary anymore.
+ // TODO: remove the widget and use the parent one insted of it
+ return PartSet_WidgetShapeSelector::setObject(theSelectedObject, theShape);
+ /*ObjectPtr aSelectedObject = theSelectedObject;
FeaturePtr aFeature = ModelAPI_Feature::feature(aSelectedObject);
if (aFeature) {
return false;
}
}
- return ModuleBase_WidgetShapeSelector::setObject(aSelectedObject, theShape);
+ return ModuleBase_WidgetShapeSelector::setObject(aSelectedObject, theShape);*/
}
if (aSelectedFeature.get() != NULL) {
std::shared_ptr<SketchPlugin_Feature> aSPFeature =
std::dynamic_pointer_cast<SketchPlugin_Feature>(aSelectedFeature);
- if ((!aSPFeature) && (!aShape.IsNull()))
- PartSet_Tools::createFixedObjectByExternal(aShape, aObject, mySketch);
+ if ((!aSPFeature) && (!aShape.IsNull())) {
+ ResultPtr aFixedObject = PartSet_Tools::findFixedObjectByExternal(aShape, aObject, mySketch);
+ if (!aFixedObject.get())
+ aFixedObject = PartSet_Tools::createFixedObjectByExternal(aShape, aObject, mySketch);
+ }
}
double aX, aY;
if (getPoint2d(aView, aShape, aX, aY)) {
std::shared_ptr<SketchPlugin_Feature> aSPFeature =
std::dynamic_pointer_cast<SketchPlugin_Feature>(aSelectedFeature);
if (aSPFeature.get() == NULL && aShape.get() != NULL && !aShape->isNull()) {
- // Processing of external (non-sketch) object
- createExternal(theSelectedObject, theShape);
- if (myExternalObject)
- aSelectedObject = myExternalObject;
- else
- return false;
+ aSelectedObject = PartSet_Tools::findFixedObjectByExternal(theShape->impl<TopoDS_Shape>(),
+ theSelectedObject, mySketch);
+ if (!aSelectedObject.get()) {
+ // Processing of external (non-sketch) object
+ aSelectedObject = PartSet_Tools::createFixedObjectByExternal(theShape->impl<TopoDS_Shape>(),
+ theSelectedObject, mySketch);
+ if (aSelectedObject.get())
+ myExternalObject = aSelectedObject;
+ }
} else {
// Processing of sketch object
DataPtr aData = myFeature->data();
removeExternal();
}
-//********************************************************************
-void PartSet_WidgetShapeSelector::createExternal(ObjectPtr theSelectedObject,
- GeomShapePtr theShape)
-{
- ObjectPtr aObj = PartSet_Tools::createFixedObjectByExternal(theShape->impl<TopoDS_Shape>(),
- theSelectedObject, mySketch);
- if (aObj != myExternalObject) {
- removeExternal();
- myExternalObject = aObj;
- }
-}
-
//********************************************************************
void PartSet_WidgetShapeSelector::removeExternal()
{
DocumentPtr aDoc = myExternalObject->document();
FeaturePtr aFeature = ModelAPI_Feature::feature(myExternalObject);
if (aFeature.get() != NULL) {
- // 1. check whether the external object can be deleted
- // It should not be deleted if there are references to the object from other features,
- // which are not the sketch or a rigid constraints.
- std::set<FeaturePtr> aRefFeatures;
- aFeature->document()->refsToFeature(aFeature, aRefFeatures, false);
- std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
- aLast = aRefFeatures.end();
- bool aReferenceExist = false;
- CompositeFeaturePtr aSketch = sketch();
- for (; anIt != aLast && !aReferenceExist; anIt++) {
- FeaturePtr aFeature = (*anIt);
- aReferenceExist = aFeature != aSketch &&
- aFeature->getKind() != SketchPlugin_ConstraintRigid::ID();
- }
- if (aReferenceExist)
- return;
-
- // 2. delete external object
QObjectPtrList anObjects;
anObjects.append(aFeature);
// the external feature should be removed with all references, sketch feature should be ignored
/// \param theValid a boolean flag, if restore happens for valid parameters
void restoreAttributeValue(const bool theValid);
- // Removes the external presentation from the model
- /// \param theSelectedObject an object
- /// \param theShape a selected shape, which is used in the selection attribute
- void createExternal(ObjectPtr theSelectedObject, GeomShapePtr theShape);
-
// Removes the external presentation from the model
void removeExternal();