return ModelAPI_Session::get()->moduleDocument();
}
-std::shared_ptr<GeomDataAPI_Point2D> PartSet_Tools::getFeaturePoint(FeaturePtr theFeature,
+/*std::shared_ptr<GeomDataAPI_Point2D> PartSet_Tools::getFeaturePoint(FeaturePtr theFeature,
double theX, double theY)
{
std::shared_ptr<GeomAPI_Pnt2d> aClickedPoint = std::shared_ptr<GeomAPI_Pnt2d>(
}
return aFPoint;
-}
+}*/
void PartSet_Tools::setFeatureValue(FeaturePtr theFeature, double theValue,
const std::string& theAttribute)
aFeature->execute();
}
-std::shared_ptr<GeomDataAPI_Point2D> PartSet_Tools::
+/*std::shared_ptr<GeomDataAPI_Point2D> PartSet_Tools::
findAttributePoint(CompositeFeaturePtr theSketch, double theX, double theY,
double theTolerance, const QList<FeaturePtr>& theIgnore)
{
}
}
return std::shared_ptr<GeomDataAPI_Point2D>();
-}
+}*/
void PartSet_Tools::setConstraints(CompositeFeaturePtr theSketch, FeaturePtr theFeature,
/// \param theY Y coordinate
/// \param theTolerance tolerance
/// \param theIgnore list of features which has to be ignored
- static std::shared_ptr<GeomDataAPI_Point2D> findAttributePoint(CompositeFeaturePtr theSketch,
- double theX, double theY, double theTolerance, const QList<FeaturePtr>& theIgnore = QList<FeaturePtr>());
+ //static std::shared_ptr<GeomDataAPI_Point2D> findAttributePoint(CompositeFeaturePtr theSketch,
+ // double theX, double theY, double theTolerance, const QList<FeaturePtr>& theIgnore = QList<FeaturePtr>());
/// Returns a point attribute of the feature by the coordinates if it is
/// \param theFeature the feature
/// \param theX the horizontal coordinate
/// \param theY the vertical coordinate
- static std::shared_ptr<GeomDataAPI_Point2D> getFeaturePoint(FeaturePtr theFeature,
- double theX, double theY);
+ //static std::shared_ptr<GeomDataAPI_Point2D> getFeaturePoint(FeaturePtr theFeature,
+ // double theX, double theY);
/// \brief Save the double to the feature. If the attribute is double, it is filled.
/// \param theFeature the feature
#include <SelectMgr_IndexedMapOfOwner.hxx>
#include <StdSelect_BRepOwner.hxx>
+//#define DEBUG_EMPTY_SHAPE
+
PartSet_WidgetShapeSelector::PartSet_WidgetShapeSelector(QWidget* theParent,
ModuleBase_IWorkshop* theWorkshop,
const Config_WidgetAPI* theData,
std::shared_ptr<SketchPlugin_Feature> aSPFeature =
std::dynamic_pointer_cast<SketchPlugin_Feature>(aSelectedFeature);
// Processing of sketch object
- if (aSPFeature.get() != NULL && theShape.get())
+#ifdef DEBUG_EMPTY_SHAPE
+ if (aSPFeature.get() != NULL && theShape.get()) {
setPointAttribute(theSelectedObject, theShape);
+#else
+ if (aSPFeature.get() != NULL) {
+ GeomShapePtr aShape = theShape;
+ if (!aShape.get()) {
+ ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theSelectedObject);
+ if (aResult.get()) {
+ aShape = aResult->shape();
+ }
+ }
+ setPointAttribute(theSelectedObject, aShape);
+#endif
+ }
else
ModuleBase_WidgetShapeSelector::setObject(theSelectedObject, theShape);
}
return false;
DataPtr aData = data();
+ std::shared_ptr<GeomAPI_Ax3> aPlane = SketchPlugin_Sketch::plane(sketch());
std::shared_ptr<GeomDataAPI_Point2D> aPoint_A = SketcherPrs_Tools::getFeaturePoint(
- aData, SketchPlugin_Constraint::ENTITY_A());
+ aData, SketchPlugin_Constraint::ENTITY_A(), aPlane);
std::shared_ptr<GeomDataAPI_Point2D> aPoint_B = SketcherPrs_Tools::getFeaturePoint(
- aData, SketchPlugin_Constraint::ENTITY_B());
+ aData, SketchPlugin_Constraint::ENTITY_B(), aPlane);
std::shared_ptr<GeomAPI_Pnt2d> aPnt_A;
std::shared_ptr<GeomAPI_Pnt2d> aPnt_B;
// Recalculate a shift of flyout point in terms of local coordinates
std::shared_ptr<GeomAPI_XY> aDir(new GeomAPI_XY(theDeltaX, theDeltaY));
+ std::shared_ptr<GeomAPI_Ax3> aPlane = SketchPlugin_Sketch::plane(sketch());
std::shared_ptr<GeomDataAPI_Point2D> aPointA = SketcherPrs_Tools::getFeaturePoint(
- data(), SketchPlugin_Constraint::ENTITY_A());
+ data(), SketchPlugin_Constraint::ENTITY_A(), aPlane);
std::shared_ptr<GeomDataAPI_Point2D> aPointB = SketcherPrs_Tools::getFeaturePoint(
- data(), SketchPlugin_Constraint::ENTITY_B());
+ data(), SketchPlugin_Constraint::ENTITY_B(), aPlane);
std::shared_ptr<GeomAPI_XY> aStartPnt;
std::shared_ptr<GeomAPI_XY> aEndPnt;
myFlyoutUpdate = false;
}
-double SketchPlugin_ConstraintDistance::calculateCurrentDistance() const
+double SketchPlugin_ConstraintDistance::calculateCurrentDistance()
{
double aDistance = -1.;
std::shared_ptr<ModelAPI_Data> aData = data();
+ std::shared_ptr<GeomAPI_Ax3> aPlane = SketchPlugin_Sketch::plane(sketch());
std::shared_ptr<GeomDataAPI_Point2D> aPointA =
- SketcherPrs_Tools::getFeaturePoint(aData, SketchPlugin_Constraint::ENTITY_A());
+ SketcherPrs_Tools::getFeaturePoint(aData, SketchPlugin_Constraint::ENTITY_A(), aPlane);
std::shared_ptr<GeomDataAPI_Point2D> aPointB =
- SketcherPrs_Tools::getFeaturePoint(aData, SketchPlugin_Constraint::ENTITY_B());
+ SketcherPrs_Tools::getFeaturePoint(aData, SketchPlugin_Constraint::ENTITY_B(), aPlane);
if (aPointA.get() && aPointB.get()) { // both points
aDistance = aPointA->pnt()->distance(aPointB->pnt());
attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
std::shared_ptr<GeomAPI_Pnt2d> aFlyoutPnt = aFlyoutAttr->pnt();
+ std::shared_ptr<GeomAPI_Ax3> aPlane = SketchPlugin_Sketch::plane(sketch());
std::shared_ptr<GeomDataAPI_Point2D> aPointA = SketcherPrs_Tools::getFeaturePoint(
- data(), SketchPlugin_Constraint::ENTITY_A());
+ data(), SketchPlugin_Constraint::ENTITY_A(), aPlane);
std::shared_ptr<GeomDataAPI_Point2D> aPointB = SketcherPrs_Tools::getFeaturePoint(
- data(), SketchPlugin_Constraint::ENTITY_B());
+ data(), SketchPlugin_Constraint::ENTITY_B(), aPlane);
std::shared_ptr<GeomAPI_XY> aStartPnt;
std::shared_ptr<GeomAPI_XY> aEndPnt;
SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
/// Returns the current distance between the feature attributes
- double calculateCurrentDistance() const;
+ double calculateCurrentDistance();
/// Customize presentation of the feature
virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
return aNewFeature;
}
+
+std::shared_ptr<GeomAPI_Ax3> SketchPlugin_Sketch::plane(SketchPlugin_Sketch* theSketch)
+{
+ std::shared_ptr<ModelAPI_Data> aData = theSketch->data();
+
+ std::shared_ptr<GeomDataAPI_Point> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
+ aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
+ std::shared_ptr<GeomDataAPI_Dir> aDirX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+ aData->attribute(SketchPlugin_Sketch::DIRX_ID()));
+ std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+ aData->attribute(SketchPlugin_Sketch::NORM_ID()));
+
+ return std::shared_ptr<GeomAPI_Ax3>(new GeomAPI_Ax3(anOrigin->pnt(), aDirX->dir(), aNorm->dir()));
+}
static FeaturePtr addUniqueNamedCopiedFeature(FeaturePtr aFeature,
SketchPlugin_Sketch* theSketch);
+ /// Creates a plane of the sketch.
+ /// \param theSketch a sketch intance
+ static std::shared_ptr<GeomAPI_Ax3> plane(SketchPlugin_Sketch* theSketch);
+
/// Customize presentation of the feature
virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
// If it is a line then we have to check that first attribute id not a line
- std::shared_ptr<GeomDataAPI_Point2D> aPoint = SketcherPrs_Tools::getFeaturePoint(aFeature->data(), aParamA);
+ std::shared_ptr<SketchPlugin_Feature> aSFeature =
+ std::dynamic_pointer_cast<SketchPlugin_Feature>(theAttribute->owner());
+ SketchPlugin_Sketch* aSketch = aSFeature->sketch();
+ std::shared_ptr<GeomAPI_Ax3> aPlane = SketchPlugin_Sketch::plane(aSketch);
+ std::shared_ptr<GeomDataAPI_Point2D> aPoint = SketcherPrs_Tools::getFeaturePoint(
+ aFeature->data(), aParamA, aPlane);
if (aPoint)
return true;
}
AIS_LengthDimension::Compute(thePresentationManager, thePresentation, theMode);
}
-bool SketcherPrs_LengthDimension::getPoints(gp_Pnt& thePnt1, gp_Pnt& thePnt2) const
+bool SketcherPrs_LengthDimension::getPoints(gp_Pnt& thePnt1, gp_Pnt& thePnt2)
{
DataPtr aData = myConstraint->data();
if (myConstraint->getKind() == SketchPlugin_ConstraintLength::ID()) {
} else if (myConstraint->getKind() == SketchPlugin_ConstraintDistance::ID()) {
std::shared_ptr<GeomDataAPI_Point2D> aPoint_A = SketcherPrs_Tools::getFeaturePoint(
- aData, SketchPlugin_Constraint::ENTITY_A());
+ aData, SketchPlugin_Constraint::ENTITY_A(), myPlane);
std::shared_ptr<GeomDataAPI_Point2D> aPoint_B = SketcherPrs_Tools::getFeaturePoint(
- aData, SketchPlugin_Constraint::ENTITY_B());
+ aData, SketchPlugin_Constraint::ENTITY_B(), myPlane);
std::shared_ptr<GeomAPI_Pnt2d> aPnt_A;
std::shared_ptr<GeomAPI_Pnt2d> aPnt_B;
const Standard_Integer aMode);
private:
- bool getPoints(gp_Pnt& thePnt1, gp_Pnt& thePnt2) const;
+ bool getPoints(gp_Pnt& thePnt1, gp_Pnt& thePnt2);
/// Constraint feature
ModelAPI_Feature* myConstraint;
#include <GeomDataAPI_Point2D.h>
#include <GeomAPI_Lin2d.h>
+#include <TopoDS.hxx>
+#include <TopoDS_Shape.hxx>
+#include <TopoDS_Vertex.hxx>
+
+#include <BRep_Tool.hxx>
+#include <Precision.hxx>
namespace SketcherPrs_Tools {
return std::shared_ptr<GeomAPI_Pnt2d>();
}
+//*************************************************************************************
+std::shared_ptr<GeomDataAPI_Point2D> findGeomPoint(ObjectPtr theObject,
+ const TopoDS_Shape& theShape,
+ const std::shared_ptr<GeomAPI_Ax3>& thePlane)
+{
+ std::shared_ptr<GeomDataAPI_Point2D> aGeomPoint;
+
+ FeaturePtr anObjectFeature = ModelAPI_Feature::feature(theObject);
+ if (anObjectFeature) {
+ if (theShape.ShapeType() == TopAbs_VERTEX) {
+ const TopoDS_Vertex& aShapeVertex = TopoDS::Vertex(theShape);
+ if (!aShapeVertex.IsNull()) {
+ gp_Pnt aShapePoint = BRep_Tool::Pnt(aShapeVertex);
+ std::shared_ptr<GeomAPI_Pnt> aShapeGeomPnt = std::shared_ptr<GeomAPI_Pnt>(
+ new GeomAPI_Pnt(aShapePoint.X(), aShapePoint.Y(), aShapePoint.Z()));
+
+ // find the given point in the feature attributes
+ std::list<AttributePtr> anObjectAttiributes =
+ anObjectFeature->data()->attributes(GeomDataAPI_Point2D::typeId());
+ std::list<AttributePtr>::const_iterator anIt = anObjectAttiributes.begin(),
+ aLast = anObjectAttiributes.end();
+ for (; anIt != aLast && !aGeomPoint; anIt++) {
+ std::shared_ptr<GeomDataAPI_Point2D> anAttributePoint =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(*anIt);
+
+ std::shared_ptr<GeomAPI_Pnt> anAttributePnt = thePlane->to3D(anAttributePoint->x(),
+ anAttributePoint->y());
+ if (anAttributePnt.get() &&
+ anAttributePnt->distance(aShapeGeomPnt) < Precision::Confusion()) {
+ aGeomPoint = anAttributePoint;
+ break;
+ }
+ }
+ }
+ }
+ }
+ return aGeomPoint;
+}
+
//*************************************************************************************
std::shared_ptr<GeomDataAPI_Point2D> getFeaturePoint(DataPtr theData,
- const std::string& theAttribute)
+ const std::string& theAttribute,
+ const std::shared_ptr<GeomAPI_Ax3>& thePlane)
{
std::shared_ptr<GeomDataAPI_Point2D> aPointAttr;
FeaturePtr aFeature;
std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = std::dynamic_pointer_cast<
ModelAPI_AttributeRefAttr>(theData->attribute(theAttribute));
- if (anAttr)
- aFeature = ModelAPI_Feature::feature(anAttr->object());
-
- if (aFeature && aFeature->getKind() == SketchPlugin_Point::ID())
- aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
- aFeature->data()->attribute(SketchPlugin_Point::COORD_ID()));
-
- else if (anAttr->attr()) {
- aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttr->attr());
+ if (anAttr) {
+ if (anAttr->isObject()) {
+ ObjectPtr anObject = anAttr->object();
+ aFeature = ModelAPI_Feature::feature(anObject);
+ if (aFeature && aFeature->getKind() == SketchPlugin_Point::ID()) {
+ aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ aFeature->data()->attribute(SketchPlugin_Point::COORD_ID()));
+ }
+ else {
+ ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
+ if (aRes.get()) {
+ GeomShapePtr aShape = aRes->shape();
+ if (aShape.get()) {
+ TopoDS_Shape aTDSShape = aShape->impl<TopoDS_Shape>();
+ aPointAttr = findGeomPoint(anObject, aTDSShape, thePlane);
+ }
+ }
+ }
+ }
+ else if (anAttr->attr()) {
+ aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttr->attr());
+ }
}
return aPointAttr;
}
/// Obtain the point object from specified constraint parameter
SKETCHERPRS_EXPORT std::shared_ptr<GeomDataAPI_Point2D> getFeaturePoint(DataPtr theData,
- const std::string& theAttribute);
+ const std::string& theAttribute,
+ const std::shared_ptr<GeomAPI_Ax3>& thePlane);
SKETCHERPRS_EXPORT double getArrowSize();