#include <XGUI_Workshop.h>
#include <XGUI_ModuleConnector.h>
+#include <ModuleBase_ViewerPrs.h>
+#include <ModuleBase_ISelection.h>
+
#include <SketchPlugin_Feature.h>
#include <QString>
return aSelectedObject;
}
+void PartSet_ExternalObjectsMgr::getGeomSelection(const ModuleBase_ViewerPrsPtr& thePrs,
+ ObjectPtr& theObject,
+ GeomShapePtr& theShape,
+ ModuleBase_IWorkshop* theWorkshop,
+ const CompositeFeaturePtr& theSketch,
+ const bool isInValidate)
+{
+ FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(theObject);
+ std::shared_ptr<SketchPlugin_Feature> aSPFeature =
+ std::dynamic_pointer_cast<SketchPlugin_Feature>(aSelectedFeature);
+ // there is no a sketch feature is selected, but the shape exists,
+ // try to create an exernal object
+ // TODO: unite with the same functionality in PartSet_WidgetShapeSelector
+ if (aSPFeature.get() == NULL) {
+ ObjectPtr anExternalObject = ObjectPtr();
+ GeomShapePtr anExternalShape = GeomShapePtr();
+ if (useExternal()) {
+ if (canCreateExternal()) {
+ GeomShapePtr aShape = theShape;
+ if (!aShape.get()) {
+ ResultPtr aResult = theWorkshop->selection()->getResult(thePrs);
+ if (aResult.get())
+ aShape = aResult->shape();
+ }
+ if (aShape.get() != NULL && !aShape->isNull())
+ anExternalObject =
+ externalObject(theObject, aShape, theSketch, isInValidate);
+ }
+ else { /// use objects of found selection
+ anExternalObject = theObject;
+ anExternalShape = theShape;
+ }
+ }
+ /// the object is null if the selected feature is "external"(not sketch entity feature of the
+ /// current sketch) and it is not created by object manager
+ theObject = anExternalObject;
+ theShape = anExternalShape;
+ }
+}
+
//********************************************************************
void PartSet_ExternalObjectsMgr::removeExternal(const CompositeFeaturePtr& theSketch,
const FeaturePtr& theFeature,
#include <string>
class ModuleBase_IWorkshop;
+class ModuleBase_ViewerPrs;
class XGUI_Workshop;
/**
ModuleBase_IWorkshop* theWorkshop,
const bool theTemporary);
+ /// Return an object and geom shape by the viewer presentation
+ /// \param thePrs a selection
+ /// \param theObject an output object
+ /// \param theShape a shape of the selection
+ virtual void getGeomSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs,
+ ObjectPtr& theObject,
+ GeomShapePtr& theShape,
+ ModuleBase_IWorkshop* theWorkshop,
+ const CompositeFeaturePtr& theSketch,
+ const bool isInValidate);
+
protected:
/// Delete from the document the feature of the object. It deletes all objects, which refers to
/// the deleted one. The parameter feature is ignored even it refer to the deleted object.
#include <PartSet_Tools.h>
#include <PartSet_Module.h>
#include <PartSet_SketcherReentrantMgr.h>
+#include <PartSet_ExternalObjectsMgr.h>
#include <XGUI_Tools.h>
#include <XGUI_Workshop.h>
setLayout(aLayout);
myWidgetValidator = new ModuleBase_WidgetValidator(this, myWorkshop);
+ myExternalObjectMgr = new PartSet_ExternalObjectsMgr(theData->getProperty("use_external"),
+ theData->getProperty("can_create_external"), true);
}
bool PartSet_WidgetPoint2D::isValidSelectionCustom(const ModuleBase_ViewerPrsPtr& theValue)
// restores the current values of the widget attribute
myWidgetValidator->restoreAttributeValue(aRefAttr, aValid);
+ myExternalObjectMgr->removeExternal(sketch(), myFeature, myWorkshop, true);
ModuleBase_WidgetValidated::blockFeatureAttribute(aRefAttr, myFeature, false, isFlushesActived,
isAttributeSetInitializedBlocked, isAttributeSendUpdatedBlocked);
double aX, aY;
const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
if (getPoint2d(aView, aTDShape, aX, aY)) {
- fillRefAttribute(aX, aY);
+ fillRefAttribute(aX, aY, theValue);
isDone = true;
}
else if (aTDShape.ShapeType() == TopAbs_EDGE) {
- fillRefAttribute(theValue->object());
+ fillRefAttribute(theValue);
isDone = true;
}
}
PartSet_WidgetPoint2D::~PartSet_WidgetPoint2D()
{
+ delete myExternalObjectMgr;
}
bool PartSet_WidgetPoint2D::setSelection(QList<ModuleBase_ViewerPrsPtr>& theValues,
const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
if (getPoint2d(aView, aTDShape, aX, aY)) {
isDone = setPoint(aX, aY);
- setConstraintToPoint(aX, aY);
+ setConstraintToPoint(aX, aY, aValue);
}
}
}
return false;
}
-bool PartSet_WidgetPoint2D::setConstraintToPoint(double theClickedX, double theClickedY)
+bool PartSet_WidgetPoint2D::setConstraintToPoint(double theClickedX, double theClickedY,
+ const std::shared_ptr<ModuleBase_ViewerPrs>& theValue)
{
AttributeRefAttrPtr aRefAttr = attributeRefAttr();
if (aRefAttr.get())
- fillRefAttribute(theClickedX, theClickedY);
+ fillRefAttribute(theClickedX, theClickedY, theValue);
else {
FeaturePtr aFeature = feature();
std::string anAttribute = attributeID();
bool isAuxiliaryFeature = false;
if (getPoint2d(aView, aShape, aX, aY)) {
setPoint(aX, aY);
- setConstraintToPoint(aX, aY);
+ setConstraintToPoint(aX, aY, aFirstValue);
}
else if (aShape.ShapeType() == TopAbs_EDGE) {
// point is taken from mouse event and set in attribute. It should be done before setting
return std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(anAttributeRef);
}
-void PartSet_WidgetPoint2D::fillRefAttribute(double theClickedX, double theClickedY)
+void PartSet_WidgetPoint2D::fillRefAttribute(double theClickedX, double theClickedY,
+ const std::shared_ptr<ModuleBase_ViewerPrs>& theValue)
{
AttributeRefAttrPtr aRefAttr = attributeRefAttr();
if (!aRefAttr.get())
aFeature, aClickedPoint);
if (aClickedFeaturePoint.get())
aRefAttr->setAttr(aClickedFeaturePoint);
+ else {
+ ObjectPtr anObject = getGeomSelection(theValue);
+ if (anObject.get())
+ aRefAttr->setObject(anObject);
+ }
}
}
+void PartSet_WidgetPoint2D::fillRefAttribute(const ModuleBase_ViewerPrsPtr& theValue)
+{
+ fillRefAttribute(getGeomSelection(theValue));
+}
+
void PartSet_WidgetPoint2D::fillRefAttribute(const ObjectPtr& theObject)
{
AttributeRefAttrPtr aRefAttr = attributeRefAttr();
}
return aFPoint;
}
+
+ObjectPtr PartSet_WidgetPoint2D::getGeomSelection(const ModuleBase_ViewerPrsPtr& theValue)
+{
+ ObjectPtr anObject;
+ GeomShapePtr aShape;
+ ModuleBase_ISelection* aSelection = myWorkshop->selection();
+ anObject = aSelection->getResult(theValue);
+ aShape = aSelection->getShape(theValue);
+ myExternalObjectMgr->getGeomSelection(theValue, anObject, aShape, myWorkshop, sketch(), true);
+
+ return anObject;
+}
class ModuleBase_ParamSpinBox;
class ModuleBase_IViewWindow;
class ModuleBase_LabelValue;
+class PartSet_ExternalObjectsMgr;
class GeomAPI_Pnt2d;
class ModuleBase_IWorkshop;
/// Creates constrains of the clicked point
/// \param theClickedX the horizontal coordnate of the point
/// \param theClickedY the vertical coordnate of the point
- bool setConstraintToPoint(double theClickedX, double theClickedY);
+ bool setConstraintToPoint(double theClickedX, double theClickedY,
+ const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
/// Create a coincidence constraint between the attribute and the parameter object
/// \theObject a result object
/// Finds first equal point attribute in sketch and set it to reference attribute
/// \param theClickedX the horizontal coordnate of the point
/// \param theClickedY the vertical coordnate of the point
- void fillRefAttribute(double theClickedX, double theClickedY);
+ void fillRefAttribute(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
+ void fillRefAttribute(double theClickedX, double theClickedY,
+ const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
void fillRefAttribute(const ObjectPtr& theObject);
+ ObjectPtr getGeomSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
+
protected:
ModuleBase_IWorkshop* myWorkshop; ///< workshop
//ModuleBase_ParamSpinBox* myYSpin; ///< the spin box for the Y coordinate
ModuleBase_LabelValue* myXSpin; ///< the label for the X coordinate
ModuleBase_LabelValue* myYSpin; ///< the label for the Y coordinate
+ PartSet_ExternalObjectsMgr* myExternalObjectMgr; ///< reference to external objects manager
/// value used as selection in mouse release method
std::shared_ptr<ModuleBase_ViewerPrs> myPreSelected;
{
ModuleBase_WidgetShapeSelector::getGeomSelection(thePrs, theObject, theShape);
+ myExternalObjectMgr->getGeomSelection(thePrs, theObject, theShape,
+ myWorkshop, sketch(), myIsInValidate);
+ /*
FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(theObject);
std::shared_ptr<SketchPlugin_Feature> aSPFeature =
std::dynamic_pointer_cast<SketchPlugin_Feature>(aSelectedFeature);
/// current sketch) and it is not created by object manager
theObject = anExternalObject;
theShape = anExternalShape;
- }
+ }*/
}
//********************************************************************