1. The cross product for a line to find the constraint direction relatively to the source line feature
return boost::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(aResult.X(), aResult.Y()));
}
+double GeomAPI_Lin2d::crossed(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint) const
+{
+ const gp_XY& aDir = MY_LIN2D->Direction().XY();
+ const gp_XY& aLoc = MY_LIN2D->Location().XY();
+ const gp_XY& aPnt = thePoint->impl<gp_Pnt2d>().XY();
+
+ return aDir.Crossed(aPnt - aLoc);
+}
const boost::shared_ptr<GeomAPI_Pnt2d> intersect(const boost::shared_ptr<GeomAPI_Lin2d>& theLine) const;
/// Project point on line
const boost::shared_ptr<GeomAPI_Pnt2d> project(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint) const;
+ /// Computes the cross product of the line direction and a vector from the line start point to the point
+ double crossed(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint) const;
};
#endif
{}
};
+//! Pointer on double attribute
+typedef boost::shared_ptr<ModelAPI_AttributeDouble> AttributeDoublePtr;
+
#endif
bool ModuleBase_WidgetDoubleValue::storeValue(FeaturePtr theFeature) const
{
DataPtr aData = theFeature->data();
- boost::shared_ptr<ModelAPI_AttributeDouble> aReal = aData->real(attributeID());
+ AttributeDoublePtr aReal = aData->real(attributeID());
if (aReal->value() != mySpinBox->value()) {
aReal->setValue(mySpinBox->value());
Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
bool ModuleBase_WidgetDoubleValue::restoreValue(FeaturePtr theFeature)
{
DataPtr aData = theFeature->data();
- boost::shared_ptr<ModelAPI_AttributeDouble> aRef = aData->real(attributeID());
+ AttributeDoublePtr aRef = aData->real(attributeID());
bool isBlocked = mySpinBox->blockSignals(true);
mySpinBox->setValue(aRef->value());
#include <PartSet_FeatureLengthPrs.h>
#include <PartSet_Tools.h>
+#include <PartSet_FeatureLinePrs.h>
+
#include <SketchPlugin_Feature.h>
#include <SketchPlugin_Sketch.h>
#include <SketchPlugin_Line.h>
#include <GeomDataAPI_Point2D.h>
#include <GeomAPI_Pnt2d.h>
+#include <GeomAPI_Lin2d.h>
#include <ModelAPI_Data.h>
#include <ModelAPI_Document.h>
#include <ModelAPI_AttributeRefAttr.h>
#include <ModelAPI_AttributeRefList.h>
+#include <ModelAPI_AttributeDouble.h>
#include <Precision.hxx>
}
break;
case SM_SecondPoint: {
- /*boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
- boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
- (aData->attribute(CIRCLE_ATTR_CENTER));
- boost::shared_ptr<GeomAPI_Pnt2d> aCoordPoint(new GeomAPI_Pnt2d(theX, theY));
- double aRadius = aCoordPoint->distance(aPoint->pnt());
- PartSet_Tools::setFeatureValue(feature(), aRadius, CIRCLE_ATTR_RADIUS);
-
- aMode = SM_DonePoint;*/
- }
+ boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
+ boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_A));
+ FeaturePtr aFeature;
+ if (anAttr) {
+ aFeature = anAttr->feature();
+ if (aFeature->getKind() != SKETCH_LINE_KIND) {
+ aFeature = FeaturePtr();
+ }
+ }
+ boost::shared_ptr<GeomAPI_Pnt2d> aPoint = boost::shared_ptr<GeomAPI_Pnt2d>
+ (new GeomAPI_Pnt2d(theX, theY));
+ boost::shared_ptr<GeomAPI_Lin2d> aFeatureLin = PartSet_FeatureLinePrs::createLin2d(aFeature);
+ boost::shared_ptr<GeomAPI_Pnt2d> aResult = aFeatureLin->project(aPoint);
+ double aDistance = aPoint->distance(aResult);
+
+ double aStartX, aStartY;
+ PartSet_FeatureLinePrs::getLinePoint(aFeature, LINE_ATTR_START, aStartX, aStartY);
+
+ if (aFeatureLin->crossed(aPoint) < 0)
+ aDistance = -aDistance;
+
+ AttributeDoublePtr aFlyoutAttr =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE));
+ aFlyoutAttr->setValue(aDistance);
+
+ aMode = SM_DonePoint;
+ }
break;
default:
break;
double& theX, double& theY)
{
if (theFeature && theFeature->getKind() == getKind()) {
- double X0, X1, X2, X3;
- double Y0, Y1, Y2, Y3;
- getLinePoint(theFeature, LINE_ATTR_START, X2, Y2);
- getLinePoint(theFeature, LINE_ATTR_END, X3, Y3);
+ double X0, X1;
+ double Y0, Y1;
PartSet_Tools::convertTo2D(thePoint, sketch(), theView, X1, Y1);
boost::shared_ptr<GeomAPI_Pnt2d> aPoint = boost::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(X1, Y1));
- boost::shared_ptr<GeomAPI_Lin2d> aFeatureLin = boost::shared_ptr<GeomAPI_Lin2d>
- (new GeomAPI_Lin2d(X2, Y2, X3, Y3));
+ boost::shared_ptr<GeomAPI_Lin2d> aFeatureLin = PartSet_FeatureLinePrs::createLin2d(theFeature);
+
switch (theMode) {
case SM_FirstPoint: {
boost::shared_ptr<GeomAPI_Pnt2d> aResult = aFeatureLin->project(aPoint);
return aPoint2D;
}
+boost::shared_ptr<GeomAPI_Lin2d> PartSet_FeatureLinePrs::createLin2d(FeaturePtr theFeature)
+{
+ boost::shared_ptr<GeomAPI_Lin2d> aFeatureLin;
+ if (!theFeature || theFeature->getKind() != PartSet_FeatureLinePrs::getKind())
+ return aFeatureLin;
+
+ double aStartX, aStartY, anEndX, anEndY;
+ getLinePoint(theFeature, LINE_ATTR_START, aStartX, aStartY);
+ getLinePoint(theFeature, LINE_ATTR_END, anEndX, anEndY);
+
+ aFeatureLin = boost::shared_ptr<GeomAPI_Lin2d>
+ (new GeomAPI_Lin2d(aStartX, aStartY, anEndX, anEndY));
+ return aFeatureLin;
+}
+
boost::shared_ptr<GeomDataAPI_Point2D> PartSet_FeatureLinePrs::featurePoint
(const PartSet_SelectionMode& theMode)
{
#include <gp_Pnt.hxx>
class GeomDataAPI_Point2D;
+class GeomAPI_Lin2d;
class Handle_V3d_View;
/*!
virtual boost::shared_ptr<GeomDataAPI_Point2D> findPoint(FeaturePtr theFeature, double theX,
double theY);
+ /// Creates a lin 2d object on a base of the line feature
+ /// \param theFeature the line feature
+ static boost::shared_ptr<GeomAPI_Lin2d> createLin2d(FeaturePtr theFeature);
+ /// \brief Get the line point 2d coordinates.
+ /// \param theFeature the line feature
+ /// \param theAttribute the start or end attribute of the line
+ /// \param theX the horizontal coordinate
+ /// \param theY the vertical coordinate
+ static void getLinePoint(FeaturePtr theFeature, const std::string& theAttribute,
+ double& theX, double& theY);
+
protected:
/// Initializes current feature by the given
/// \param theSourceFeature the feature, which attributes are used to initialize the current feature
/// Returns the feature point in the selection mode position.
/// \param theMode the current operation selection mode. The feature attribute depends on the mode
virtual boost::shared_ptr<GeomDataAPI_Point2D> featurePoint(const PartSet_SelectionMode& theMode);
-
- /// \brief Get the line point 2d coordinates.
- /// \param theFeature the line feature
- /// \param theAttribute the start or end attribute of the line
- /// \param theX the horizontal coordinate
- /// \param theY the vertical coordinate
- static void getLinePoint(FeaturePtr theFeature, const std::string& theAttribute,
- double& theX, double& theY);
};
#endif
{
boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
- boost::shared_ptr<ModelAPI_AttributeDouble> anAttr =
+ AttributeDoublePtr anAttr =
boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_VALUE));
anAttr->setValue(theValue);
bool PartSet_OperationCreateConstraint::canProcessKind(const std::string& theId)
{
- return /*theId == SKETCH_LINE_KIND || theId == SKETCH_POINT_KIND || theId == SKETCH_CIRCLE_KIND ||
- theId == SKETCH_ARC_KIND || */theId == SKETCH_CONSTRAINT_LENGTH_KIND;
+ // changed
+ return theId == SKETCH_CONSTRAINT_LENGTH_KIND;
}
bool PartSet_OperationCreateConstraint::canBeCommitted() const
const std::list<XGUI_ViewerPrs>& /*theSelected*/,
const std::list<XGUI_ViewerPrs>& /*theHighlighted*/)
{
- if (!theFeature || theFeature->getKind() != SKETCH_LINE_KIND)
+ // changed
+ if (!theFeature/* || theFeature->getKind() != SKETCH_LINE_KIND*/)
return;
myInitFeature = theFeature;
}
const std::list<XGUI_ViewerPrs>& theSelected,
const std::list<XGUI_ViewerPrs>& /*theHighlighted*/)
{
- if (theSelected.empty()) {
-
- }
- else {
- XGUI_ViewerPrs aPrs = theSelected.front();
- FeaturePtr aFeature = aPrs.feature();
+ switch (myPointSelectionMode)
+ {
+ case SM_FirstPoint: {
+ if (!theSelected.empty()) {
+ XGUI_ViewerPrs aPrs = theSelected.front();
+ FeaturePtr aFeature = aPrs.feature();
+
+ myFeaturePrs->init(feature(), aFeature);
+ flushUpdated();
+ setPointSelectionMode(SM_SecondPoint);
+ }
+ }
+ break;
+ case SM_SecondPoint: {
+ double aX, anY;
+ gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView);
+ PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
- myFeaturePrs->init(feature(), aFeature);
- flushUpdated();
+ PartSet_SelectionMode aMode = myFeaturePrs->setPoint(aX, anY, myPointSelectionMode);
+ flushUpdated();
+ // show value edit dialog
+ //setPointSelectionMode(aMode);
+ commit();
+ restartOperation(feature()->getKind(), FeaturePtr());
+ }
+ break;
+ default:
+ break;
}
}
void PartSet_OperationCreateConstraint::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
{
+ // changed
switch (myPointSelectionMode)
{
- case SM_FirstPoint:
+ //case SM_FirstPoint:
case SM_SecondPoint:
- case SM_ThirdPoint:
+ //case SM_ThirdPoint:
{
double aX, anY;
gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView);
if (feature()) {
boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
- boost::shared_ptr<ModelAPI_AttributeDouble> anAttr;
+ AttributeDoublePtr anAttr;
boost::shared_ptr<GeomDataAPI_Dir> aNormal =
boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_NORM));
aHasPlane = aNormal && !(aNormal->x() == 0 && aNormal->y() == 0 && aNormal->z() == 0);
//Build dimension here
gp_Pnt aP1 = aPoint1;
gp_Pnt aP2 = aPoint2;
+ if (aFlyout < 0) {
+ aP1 = aPoint2;
+ aP2 = aPoint1;
+ }
+
Handle(AIS_InteractiveObject) anAIS = thePrevPrs;
if (anAIS.IsNull())
Handle(AIS_LengthDimension) aDimAIS = Handle(AIS_LengthDimension)::DownCast(anAIS);
if (!aDimAIS.IsNull()) {
aDimAIS->SetMeasuredGeometry(aPoint1, aPoint2, aPlane);
+ aDimAIS->SetFlyout(aFlyout);
+
aDimAIS->Redisplay(Standard_True);
}
}
if (!theSketch)
return;
- boost::shared_ptr<ModelAPI_AttributeDouble> anAttr;
+ AttributeDoublePtr anAttr;
boost::shared_ptr<ModelAPI_Data> aData = theSketch->data();
boost::shared_ptr<GeomDataAPI_Point> anOrigin =
if (!theFeature)
return;
boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
- boost::shared_ptr<ModelAPI_AttributeDouble> anAttribute =
+ AttributeDoublePtr anAttribute =
boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(theAttribute));
if (anAttribute)
anAttribute->setValue(theValue);
if (aHasPlane) {
boost::shared_ptr<GeomAPI_Dir> aNormal(new GeomAPI_Dir(aNDir->x(), aNDir->y(), aNDir->z()));
// compute the circle radius
- boost::shared_ptr<ModelAPI_AttributeDouble> aRadiusAttr =
+ AttributeDoublePtr aRadiusAttr =
boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(data()->attribute(CIRCLE_ATTR_RADIUS));
double aRadius = aRadiusAttr->value();
// Create constraint parameters
double aDistance = 0.0; // scalar value of the constraint
- boost::shared_ptr<ModelAPI_AttributeDouble> aDistAttr =
+ AttributeDoublePtr aDistAttr =
boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(theConstraint->data()->attribute(CONSTRAINT_ATTR_VALUE));
if (aDistAttr)
{
}
// Scalar value (used for the distance entities)
- boost::shared_ptr<ModelAPI_AttributeDouble> aScalar =
+ AttributeDoublePtr aScalar =
boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(theEntity);
if (aScalar)
{
}
// Scalar value
- boost::shared_ptr<ModelAPI_AttributeDouble> aScalar =
+ AttributeDoublePtr aScalar =
boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(theAttribute);
if (aScalar)
{